public void sortFiles() { Iterator<Node> iterator = placeList.iterator(); Collections.sort(placeList); while (iterator.hasNext()) { Node node = iterator.next(); String nodeText = node.getTokenText(); String docId = node.getDocId(); String indexPos = String.valueOf(node.getIndexPos()); String docLen = String.valueOf(node.getDocLength()); writer.print(nodeText + " ;! " + docId + " ;! "); writer.println(indexPos + " ;! " + docLen); } writer.close(); }