How to Write an ArrayList of Strings into a Text File? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 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 info K kadambalamatclo Follow Improve Article Tags : Java Java Programs Java-Strings Java-ArrayList Java Examples +1 More Explore Java BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOP & InterfacesClasses and Objects in Java10 min readAccess Modifiers in Java6 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking15+ min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like