Question: I want to write an `ArrayList<String>` into a text file. 

The `ArrayList` is created with the code:

```
ArrayList arr = new ArrayList();

StringTokenizer st = new StringTokenizer(
    line, ":Mode set - Out of Service In Service");

while(st.hasMoreTokens()){
    arr.add(st.nextToken());    
}

```

Answer: 
You can do that with a single line of code nowadays.
Create the arrayList and the Path object representing the file where you want to write into:

```
Path out = Paths.get("output.txt");
List<String> arrayList = new ArrayList<> ( Arrays.asList ( "a" , "b" , "c" ) );

```

Create the actual file, and fill it with the text in the ArrayList: 

```
Files.write(out,arrayList,Charset.defaultCharset());

```
If you need to create each ArrayList item in a single line then you can use this code

```
private void createFile(String file, ArrayList<String> arrData)
            throws IOException {
        FileWriter writer = new FileWriter(file + ".txt");
        int size = arrData.size();
        for (int i=0;i<size;i++) {
            String str = arrData.get(i).toString();
            writer.write(str);
            if(i < size-1)**//This prevent creating a blank like at the end of the file**
                writer.write("\n");
        }
        writer.close();
    }

```