changed for to foreach and treeSet to arrayList and Collections sort