Java Tutorials

171. The TreeSet Class in Java

By: Abinaya : 2007-09-14

Description: TreeSet provides an implementation of the Set interface that uses a tree for storage. Objects are stored in sorted, ascending order. Access and retrieval times are quite fast, which makes TreeSet an excellent choice when storing large amounts of sorted information that must be found quickly.


172. iterator() and hasNext() in Java

By: Baski : 2007-09-14

Description: Before you can access a collection through an iterator, you must obtain one. Each of thecollection classes provides an iterator() method that returns an iterator to the start of the collection. By using this iterator object, you can access each element in the collection, one element at a time. In general, to use an iterator to cycle through the contents of a collection, follow these steps:


173. HashMap example in Java

By: Charles : 2007-09-14

Description: The HashMap class uses a hash table to implement the Map interface. This allows the execution time of basic operations, such as get() and put(), to remain constant even for large sets.


174. TreeMap example in Java

By: Daniel Malcolm : 2007-09-14

Description: The TreeMap class implements the Map interface by using a tree. A TreeMap provides an efficient means of storing key/value pairs in sorted order, and allows rapid retrieval. You should note that, unlike a hash map, a tree map guarantees that its elements will be sorted in ascending key order.


175. compare() example in Java

By: Emiley J : 2007-09-14

Description: The following is an example that demonstrates the power of a custom comparator. It implements the compare() method so that it operates in reverse of normal. Thus, it causes a tree set to be stored in reverse order.


176. Arrays example in Java - asList(), binarySearch(), fill(), sort(), equals()

By: Fazal : 2007-09-14

Description: Java 2 added a new class to java.util called Arrays. This class provides various methods that are useful when working with arrays. Although these methods technically aren't part of the collections framework, they help bridge the gap between collections and arrays. Each method defined by Arrays is examined in this tutorial.


177. Vector example in Java

By: Grenfel : 2007-09-14

Description: Vector implements a dynamic array. It is similar to ArrayList, but with two differences: Vector is synchronized, and it contains many legacy methods that are not part of the collections framework. With the release of Java 2, Vector was reengineered to extend AbstractList and implement the List interface, so it now is fully compatible with collections.


178. Hashtable example in Java

By: Ivan Lim : 2007-09-14

Description: Hashtable was part of the original java.util and is a concrete implementation of a Dictionary. However, Java 2 reengineered Hashtable so that it also implements the Map interface. Thus, Hashtable is now integrated into the collections framework. It is similar to HashMap, but is synchronized.


179. Properties example in Java

By: Jagan : 2007-09-14

Description: Properties is a subclass of Hashtable. It is used to maintain lists of values in which the key is a String and the value is also a String. The Properties class is used by many other Java classes. For example, it is the type of object returned by System.getProperties() when obtaining environmental values.


180. BitSet example in Java

By: Lakshmi : 2007-09-14

Description: A BitSet class creates a special type of array that holds bit values. This array can increase in size as needed. This makes it similar to a vector of bits. The BitSet constructors are shown here: