1 package org.feistymeow.example;
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
8 public class ZSorter<T extends Comparable<? super T>> {
11 * returns a new list which is the sorted version of the input
14 public List<T> sort(List<T> toSort) {
15 List<T> toReturn = new ArrayList<T>(toSort);
16 Collections.copy(toReturn, toSort);
17 Collections.sort(toReturn);
22 * simple console printer for list of T.
24 public void print(List<T> toPrint) {
26 for (T curr: toPrint) {
27 if (!first) System.out.print(", ");
29 System.out.print(curr);
34 public static void main(String[] args) {
35 ZSorter<Integer> sorter = new ZSorter<Integer>();
38 = new ArrayList<Integer>(Arrays.asList(101, 19, 86, 72, 56, 35, 47));
39 System.out.println("prior to sorting:");
40 sorter.print(theList);
42 // test our sort method.
43 List<Integer> newList = sorter.sort(theList);
44 System.out.println("after sorting:");
45 sorter.print(newList);