Category Archive for: java util Part 1 The Collections Framework

Using store( ) and load( )

Using store( ) and load( ) One of the most useful aspects of Properties is that the information contained in a . Properties object can be easily stored to or loaded from disk with the store( ) and load( ) methods. At any time, you can write a Properties object to a stream or read it back. This makes…

Read More →

Properties

Properties Properties is a subclass of Hash table, It is used to maintain lists of values in which the key is a String and the value is also a String. TI,e Properties class is used by many , ‘ other Java classes. For example, it is the type of object returned by System get Properties( ) when obtaining…

Read More →

Stack

Stack Stack is a subclass of Vector that implements, a standard last-in, first-out stack. Stack only defines the default constructor, which creates an empty stack. Stack includes all the methods defined by Vector, and adds several of its own, shown in Table 15-11. To put an object on the top of the stack, call push( I, To remove…

Read More →

Enumeration interface

Enumeration interface The output from this program is.shown here: Initial size: 0 Current capacity: 9 First element: 1 Last element: 2 Vector contains: 3 Elements in vector: With the release of Java 2, Vector adds support for iterators. Instead of relying o!” an enumeration to cycle through the objects (as the preceding program does), you now can…

Read More →

Vector

Vector Vector implements a dynamic array. It is to Array List, but with two differences: Vector is synchronized, and it contains many legacy methods that are not part of the collections frame work.With the release of Java 2,Vector wast engineered to extend Abstract List and implement the List interface, so it now is fully compatible with collections Here are…

Read More →

The legacy classes and interfaces

The legacy classes and interfaces As explained at. the start of this chapter, the original version of java.utll did not include the collections framework. Instead, it defined several classes and an interface that provided an ad has method of storing objects. With the addition of collections by Java 2, several of the original classes ware engineered to support…

Read More →

Arrays

Arrays Java 2 added a new class or java.util called Arrays. This class provides various methods that <Ire useful when working with <arrays, Although these methods technically aren’t part of Collections framework, they help bridge the gap between collections and arrays, Each method defined by Arrays is examined in this section. The as List( ) method returns a List…

Read More →

Using a Comparator

Using a Comparator The following is an example that demonstrates the power of a custom comparator. II implements the compare() method so that i operates in reverse of normal. Thus, it causes a tree set to be stored in reverse order. As the following output shows, the tree is now stored in reverse order: FEDCDA Look closely at…

Read More →

Comparators

Comparators   Doth TreeSet and TreeMap store elements in sorted order. However, it is the. comparator that defines precisely what “sorted order” means. By default, these classes store their elements by using what Java refers to as “natural ordering,” which is usually the ordering that you would expect. (A beforeB, Ibefore 2, and so forth.j If you want to…

Read More →

The TreeMap Class

The TreeMap Class TIle TrecMap 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. The following TrecMap constructors are…

Read More →

Back to Top