package selectedClasses; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; /** * * @author Lefteris Moussiades */ public class ArrayLists { static void sorting(ArrayList array) { array.sort(null); System.out.println(array); Collections.shuffle(array); System.out.println(array); } static void deleting1(ArrayList l) { int end = l.size(); for (int i = 0; i < end; i++) { String name = l.get(i); //IndexOutOfBoundsException if (name.equals("Anthi")) { l.remove(i); } } } static void deleting2(ArrayList l) { Iterator it = l.iterator(); while (it.hasNext()) { String item = it.next(); if (item.equals("Anthi")) { it.remove(); } //l.remove(item); //ConcurrentModification } } public static void main(String[] args) { //ArrayList array = new ArrayList(); //array.add("Lefteris"); //array.add("Anthi"); //array.add("Giannis"); //array.add("Kwstas"); //System.out.println(array); //array.sort(null); //sorting(array); //deleting1(array); //deleting2(array); //System.out.println(array); } }