How to Write an ArrayList of Strings into a Text File? Last Updated : 02 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In Java, ArrayList is a class in the java.util package. It facilitates the creation of dynamic arrays that can dynamically grow or shrink as elements are added or removed. This class is part of the Java Collections Framework. An ArrayList of strings is converted into a text file and implemented using the BufferWriter class along with the framework. BufferWriter and FileWriterBufferWriter: It is a class in Java that is used to provide buffering for Writer instances. It makes the writing process more efficient to write the character to the file.FileWriter: It is a class in Java. It is used for writing character data into a file. It is a subclass of the Writer class and is part of the java.io package.Program to write an ArrayList of Strings into a text file in Java Java // Java Program to write an ArrayList // Of Strings into a text file import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; // Driver Class public class GFGArrayListToTextFile { public static void main(String[] args) { // Sample ArrayList of Strings ArrayList<String> strlst = new ArrayList<>(); strlst.add("Welcome to"); strlst.add("Greeks for Greeks"); strlst.add("Java"); strlst.add("tutorial"); // Specify the File Path String filePath = "C:/Users/mahalaxmi/Desktop/programs/output.txt"; // Convert ArrayList to the text file try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) { for (String str : strlst) { writer.write(str); writer.newLine(); } System.out.println("ArrayList written to file successfully."); } catch (IOException e) { e.printStackTrace(); } } } Executing the above Program:javac GFGArrayListToTextFile.javajava GFGArrayListToTextFileOutput Text File: Explanation of the above Program:The above program is example of the ArrayList string convert into the text file using the BufferWriter along with FileWriter. We have created one ArrayList names as strlst, after that using taken one string as defined the file path where the text file will be saved then using BufferWriter and FileWriter to convert the ArrayList String into the text file. Comment More infoAdvertise with us Next Article How to Write an ArrayList of Strings into a Text File? K kadambalamatclo Follow Improve Article Tags : Java Java Programs Java-Strings Java-ArrayList Java Examples +1 More Practice Tags : JavaJava-Strings Similar Reads How to Convert an ArrayList into a JSON String in Java? In Java, an ArrayList is a resizable array implementation of the List interface. It implements the List interface and is the most commonly used implementation of List. In this article, we will learn how to convert an ArrayList into a JSON string in Java. Steps to convert an ArrayList into a JSON str 2 min read How to Convert a String to ArrayList in Java? Converting String to ArrayList means each character of the string is added as a separator character element in the ArrayList. Example: Input: 0001 Output: 0 0 0 1 Input: Geeks Output: G e e k s We can easily convert String to ArrayList in Java using the split() method and regular expression. Paramet 1 min read How to Convert JSON Array to String Array in Java? JSON stands for JavaScript Object Notation. It is one of the widely used formats to exchange data by web applications. JSON arrays are almost the same as arrays in JavaScript. They can be understood as a collection of data (strings, numbers, booleans) in an indexed manner. Given a JSON array, we wil 3 min read How to Convert a Comma-Separated String into an ArrayList in Java? In Java, to convert a comma-separated string into ArrayList, we can use the split() method to break the string into an array based on the comma delimiter. Another method we can also use Java Streams for a functional approach to achieve the same result.Example:Input: "Hello,from,geeks,for,geeks"Outpu 2 min read Writing List Contents to Text File After Deleting String in Java To write a List<String> to a text file after deleting a specific string, you can use the following steps: Iterate through the List<String> and use the remove() method to remove the desired string.Open a FileWriter and BufferedWriter to write to the text file.Iterate through the modified 3 min read Like