《Java 5.0 Tiger》Chapter 1
Chapter 1. What's New?1.1 Working with Arrays

System.out.println(Arrays.toString(s1));
String[][] s2 =



System.out.println(Arrays.deepToString(s2));
String[][] s3 =



System.out.println(Arrays.deepEquals(s2, s3));



The first method to take note of, at least for Tiger fans, is toString( ). This handles the rather annoying task of printing arrays for you. While this is trivial to write on your own, it's still nice that Sun takes care of it for you now.
Another similar, but also new, method is deepToString( ). This method takes in an object array, and prints out its contents, including the contents of any arrays that it might contain.
Finally, Arrays provides a deepEquals( ) method that compares multidimensional arrays.
1.2 Using Queues
Another cool collection addition is the java.util.Queue class, for all those occasions when you need FIFO (first-in, first-out) action.







Use offer(), poll() instead of add(), remove() respectivelly. If you want the head without removing it, ues element() or peek().
In Tiger, LinkedList has been retrofitted to implement the Queue interface. While you can use it like any other List implementation, it can also be used as a Queue implementation.
1.3 Ordering Queues Using Comparators
PriorityQueue, a Queue with Comparator. If you don't specify a Comparator, natural ordering occurs.





































/* --- console output --- */

1.4 Overriding Return Types


















































































The key is the line public Point3D getLocation( ), which probably looks pretty odd to you, but get used to it. This is called a covariant return, and is only allowed if the return type of the subclass is an extension of the return type of the superclass.
1.5 Taking Advantage of Better Unicode
In Tiger, Java has moved to support Unicode 4.0, which defines several characters that don't fit into 16 bits. This means that they won't fit into a char, and that has some far-reaching consequences. You'll have to use int to represent these characters, and as a result methods like Character.isUpperCase( ) and Character.isWhitespace( ) now have variants that accept int arguments. So if you're needing values in Unicode 3.0 that are not available in Unicode 3.0, you'll need to use these new methods..
Most of the new characters in Unicode 4.0 are Han ideographs.
1.6 Adding StringBuilder to the Mix
Replace all your StringBuffer code with StringBuilder code. Really—it's as simple as that. If you're working in a single-thread environment, or in a piece of code where you aren't worried about multiple threads accessing the code, or synchronization, it's best to use StringBuilder instead of StringBuffer.
posted on 2005-12-25 16:24 Scott@JAVA 閱讀(396) 評論(0) 編輯 收藏 所屬分類: Java 5.0 Tiger