coderz.py

Keep Coding Keep Cheering!

Comparator Interface in Java Collection Framework

To sort the objects of user-defined classes, a comparator interface is utilized. A comparator object can compare two items of the same type.This interface may be found in java.util package and includes two methods: compare(Object obj1,Object obj2) equals (Object element). It supports different sorting sequences, which means you can sort the items based on any […]

August 6, 2022 | Java | No comments

Comparable Interface in Java

The Comparable interface is used to compare an object of the same class with an instance of that class; it also enables data ordering for user-defined class objects. The class has to implement the java.lang.Comparable interface to compare its instance, it provides the compareTo() method, which accepts an object of that class as an argument. Its sorting algorithm is determined by the type of object used by the interface. If the object type is a string, it is sorted lexicographically. Else, If the object type is a wrapper class object, such as an integer […]

August 5, 2022 | Java | No comments

Collections Class in Java

The Collections class belongs to the Java Collections Framework. The package java.util.Collections is the package containing the Collections class. The Collections class mainly uses static methods that operate on or return collections. If the collection or object supplied to the methods is null, all the methods in this class throw the NullPointerException. Declaration: Collections Methods: […]

August 5, 2022 | Java | No comments

Hashtable class in Java Collection Framework

The Hashtable class creates a hash table by mapping keys to values. As a key or value, any non-null object can be used. The objects used as keys must implement the hashCode and equals methods in order to successfully store and retrieve objects from a hashtable. Hashtable class Declaration: Remember the following: A Hashtable is […]

August 3, 2022 | Java | No comments

Treemap class in Java Collection Framework

Along with the AbstractMap Class, the TreeMap class in Java is used to implement the Map interface and NavigableMap. Depending on which constructor is used, the map is sorted based on the natural ordering of its keys or by a Comparator specified at map creation time. TreeMap class declaration: where, K: It is the type of […]

August 2, 2022 | Java | No comments

HashMap class in Java Collection Framework

Since Java 1.2, HashMap<K, V> class has been part of the Java collection. This class can be found in java.util package. It implements the Java Map interface in its most basic form. If you try to insert the duplicate key, it will replace the associated key’s element. The key index makes it simple to conduct […]

August 1, 2022 | Java | No comments

LinkedHashSet class in Java Collection Framework

The LinkedHashSet class is an ordered HashSet with a doubly-linked List across all entries. This class is used when the iteration order must be maintained. The order of the elements in a HashSet is unpredictable, whereas a LinkedHashSet allows us to iterate through them in the order in which they were inserted. Declaration of LinkedHashSet: […]

July 30, 2022 | Java | No comments

HashSet class in Java Collection Framework

The Java HashSet class is used to create a collection that stores data in a hash table. It derives from AbstractSet and implements the Set interface. This class allows for the null element. The class also provides constant time performance for fundamental operations such as add, delete, contains, and size, assuming the hash function properly […]

July 29, 2022 | Java | No comments

Map Interface in Java Collection Framework

Java includes a map interface. A mapping between a key and a value is represented by the util package. The Collection interface does not have a subtype called Map. As a result, it operates differently than the other collection types. A map comprises distinct keys. Duplicate keys are not permitted in a Map, although duplicate […]

July 28, 2022 | Java | No comments

Java TreeSet class

TreeSet is a widespread Java implementation of the SortedSet interface that employs a Tree for storage. Whether an explicit comparator is provided, a set maintains the ordering of the components using their natural ordering. If the Set interface is to be correctly implemented, this must be compatible with equals. TreeSet class Declaration: The following are […]

July 26, 2022 | Java | No comments

Advertisement