Explore model answers categorized by subjects like Java, HTML, DBMS, and more.
Util is a Java Package
The List interface provides support for ordered collections of objects.
The Collections API is a set of classes and interfaces that support operations on collections of objects.
The Enumeration interface allows you to iterate through all the elements of a collection. Iterating through an Enumeration is similar to iterating through an Iterator. However, there is no removal support with Enumeration.
The Enumeration interface allows you to iterate through all the elements of a collection. Iterating through an Enumeration is similar to iterating through an Iterator. However, there is no removal support with Enumeration. Basic methods: boolean hasMoreElements(); Object nextElement();
The Iterator interface is used to step through the elements of a Collection .
Java Collections Framework provides a well designed set of interfaces and classes that support operations on a collection of objects.
An Iterator is similar to the Enumeration interface. With the Iterator interface methods, you can traverse a collection from start to end and safely remove elements from the underlying collection. The iterator() method generally used in query operations. Basic methods: iterator.remove(); iterator.hasNext(); iterator.next();
HashSet and TreeSet are the two Set implementations available in the Collections Framework.
HashSet Class implements java.util.Set interface to eliminate the duplicate entries and uses hashing for storage. Hashing is nothing but mapping between a key value and a data item, this provides efficient searching. The TreeSet Class implements java.util.Set interface provides an ordered set, eliminates duplicate entries and uses tree for storage.
The ArrayList Class implements java.util.List interface and uses array for storage. An array storage’s are generally faster but we cannot insert and delete entries in middle of the list. To achieve this kind of addition and deletion requires a new array constructed. You can access any element at randomly. The LinkedList Class implements java.util.List interface and uses linked list for storage. A linked list allow elements to be added, removed from the collection at any location in the container by ordering the elements. With this implementation you can only access the elements in sequentially.
A map is a special kind of set with no duplicates. The key values are used to lookup, or index the stored data. The Map interface is not an extension of Collection interface, it has it’s own hierarchy. Map does not allow duplicates in the collection. In Map implementations null is valid entry, but allowed only once.
HashMap and TreeMap are two types of Map implementations available in the Collections Framework.
The HashMap Class implements java.util.Map interface and uses hashing for storage. Indirectly Map uses Set functionality so, it does not permit duplicates. The TreeMap Class implements java.util.Map interface and uses tree for storage. It provides the ordered map.
Once array size is set you cannot change size of the array. To deal with this kind of situations we use Vector. Vector grows and shrink it’s size automatically. Vector allows to store only objects not primitives. To store primitives, convert primitives in to objects using wrapper classes before adding them into Vector. The Vector reallocates and resizes itself automatically.
Vector vt = new Vector(3, 10); vt is an instance of Vector class with an initial capacity of 3 and grows in increment of 10 in each relocation
Vector and ArrayList are very similar. Both of them represent a growable array. The main difference is that Vector is synchronized while ArrayList is not.
Both provide key-value access to data. The key differences are : a. Hashtable is synchronised but HasMap is not synchronised. b. HashMap permits null values but Hashtable doesn’t allow null values. c. iterator in the HashMap is fail-safe while the enumerator for the Hashtable is not fail safe.
You cannot directly make an array larger. You must make a new (larger) array and copy the original elements into it, usually with System.arraycopy(). If you find yourself frequently doing this, the Vector class does this automatically for you, as long as your arrays are not of primitive data types.
The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region
The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program’s appearance to the particular locale in which it is being run.