For example, to reverse a list use:
List<Character> myList = new LinkedList<Character>();
myList.add('A');
myList.add('B');
myList.add('C');
myList.add('D');
System.out.println("Before:" + myList);
Collections.reverse(myList);
System.out.println("After: " + myList);
If your list contained Character objects for 'A', 'B', 'C', 'D' then after calling reverse it'll magically contain 'D', 'C', 'B', 'A'.
No comments:
Post a comment