Chapter 9. Java and WebSphere application design 293
Table 9-3 Java 2 Collection Framework
When you use these collections, remember these points:
The Collection interface is a group of objects, with duplicates allowed.
Set extends the Collection but forbids duplicates.
List extends Collection as well, but allows duplicates, and introduces positional indexing.
To choose the correct Collection, follow these guidelines:
Sets
Sets are slow in general.
Usually Set is the fastest set.
TreeSet is the slower set but provides iteration of keys in order.
Lists
Usually ArrayList is the fastest list.
If the list is large and elements are frequently deleted or inserted, LinkedList is faster.
Stack has the same speed as Vector and provides last in, first out (LIFO) queue
functionality.
Maps
Usually HashMap is the fastest map.
TreeMap is the slower Map but provides iteration of keys in order.
One final tip regarding performance is to use iterators whenever you can to access the
elements of a list, rather than using positional access.
9.1.9 Java Native Interface
Native method invocation on an iSeries server may not perform as well as native method
invocation on other platforms. Java on the iSeries server has been optimized by moving the
JVM below the machine interface (MI). Native method invocation requires a call to above MI
code and may require expensive Java Native Interface (JNI) calls back into the JVM. Native
methods should not carry out small routines, which you can easily write in Java. Only use
native methods to start system functions that are relatively long running and are not available
directly in Java.
Interfaces
Implementations
Hash table Resizable array Balance tree Linked list
Set HashSet TreeSet
List ArrayList LinkedList
Map HashMap TreeMap
Attention: Use care when using Collections because they may become the beginning of
memory leaks issues. If you add elements to a Collection and never delete these
references, this becomes a memory leak. Imagine an application with a Collection variable
in the servlet to insert the customers that login the application. After a while, you have a list
of all the customers that logged in the application, but if you never delete these customers
from the Collection, it will grow endlessly.

Get Maximum Performance with WebSphere Application Server V5.1 on iSeries now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.