// Java 1.5 Tiger A Developers Notebook Brett McLaughlin and David Flanagan // Goal is to save unnecessary type casting // Make code more type safe with Generics // Support Unicode 4.0 which defines characters that don't fit in 16 bit // Character.isUppercase() ... that takes int // StringBuilder which can be used instead of StringBuffer when code is not multithreaded import java.util.Arrays; import java.util.Comparator; import java.util.Queue; import java.util.PriorityQueue; //import java.lang.System.out; import java.util.LinkedList; public class Tiger1 { public static void arrays() { int[] foo1 = new int[] { 1, 2, 3}; System.out.println(Arrays.toString(foo1)); int[][] foo2 = new int[][] { {1, 2}, {3, 4} }; System.out.println(Arrays.deepToString(foo2)); int[][] foo3 = (int[][]) foo2.clone(); System.out.println(Arrays.deepToString(foo3)); if (Arrays.deepEquals(foo2, foo3)) System.out.println("deep equal"); int hashCode = Arrays.deepHashCode(foo2); } public static void queues() { System.out.println("Queues"); Queue q = new LinkedList(); // Queue is an interface implemented by LinkedList q.add("1"); q.add("2"); q.offer("3"); Object o; o = q.peek(); while ((o = q.poll()) != null) System.out.println(o); q.remove(); } public static void priorityQueue() { PriorityQueue pq = new PriorityQueue(3, new Comparator() { public int compare(Object i, Object j) { Integer i1 = (Integer) i; Integer i2 = (Integer) j; return i1.intValue() < i2.intValue() ? 1 : -1; } }); pq.offer(new Integer(1)); pq.offer(new Integer(2)); pq.offer(new Integer(3)); Object o; while ((o = pq.poll()) != null) System.out.println(o); } public static void main(String[] args) { arrays(); queues(); priorityQueue(); } } // covaraint return class foo1 { } class foo2 extends foo1 {} class use1 { foo1 getfoo() { return new foo1(); } } class use2 { foo2 getfoo() { return new foo2(); } }