ListIterator : add()

The add() method is used to add objects to a collection. This method always takes an object as an argument. If we wish to store primitive data type values, we have to convert them into objects and then add them to the collection. Program       Program Source import java.util.ArrayList; import java.util.ListIterator; public class … Read more…

Store User-Defined Objects in Collections

The power of collections is that they can store any type of object, including objects of classes that you create. For example, consider the following example that uses a LinkedList to store Store User-Defined Objects. Program Program Source import java.util.LinkedList; class StudentData { String name; int age; StudentData(String na, int ag) { name = na; age … Read more…

Java HashSet

The Hashset class extends the AbstractSet class. The HashSet class implements the Set interface. This class deals with a collection, whose elements are stored in a hash table. The hashing mechanism is used to store the elements in a hash table. This mechanism uses the informational content of a key to determine a unique value. … Read more…

Java HashSet : size() contains() remove() clear()

The remove() method shall be used to remove an unwanted object from a collection. We shall use the clear() method to completely empty a collection. The Contains() method enables us to determine whether a specific object is present in a collection or not. The size() method returns the number of elements in a collection. The … Read more…

Java TreeSet

TreeSet extends AbstractSet and implements the NavigableSet interface. It creates a collection 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. TreeSet has the following constructors: … Read more…

TreeSet : first(), last(), lower(), higher(), descendingSet()

The first() method returns the first (lowest) element currently in this set. The last() method returns the last (highest) element currently in this set. The lower() method returns the greatest element in this set strictly less than the given element, or null if there is no such element. The higher() method returns the least element in this … Read more…