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 want to serialize the ArrayList object to a file so you can read it back in again later use ObjectOuputStream/ObjectInputStream writeObject()/readObject() since ArrayList implements [Serializable](http://download.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.html). It's not clear to me from your question if you want to do this or just write each individual item. If so then Andrey's answer will do that.