Category Archives: Java

NavigableSet in Java with Examples

NavigableSet represents a navigable set in Java Collection Framework. The NavigableSet interface inherits from the SortedSet interface. It behaves like a SortedSet with the exception that we have navigation methods available in addition to the sorting mechanisms of the SortedSet. For example, NavigableSet interface can navigate the set in reverse order compared to the order… Read More »

SortedMap Interface in Java with Examples

SortedMap is an interface in collection framework. This interface extends Map inrerface and provides a total ordering of its elements (elements can be traversed in sorted order of keys). Exampled class that implements this interface is TreeMap. The main characteristic of a SortedMap is that, it orders the keys by their natural ordering, or by… Read More »

Map interface in Java with examples

The java.util.Map interface represents a mapping between a key and a value. The Map interface is not a subtype of the Collection interface. Therefore it behaves a bit different from the rest of the collection types. A Map cannot contain duplicate keys and each key can map to at most one value. Some implementations allow… Read More »

Split() String method in Java with examples

The string split() method breaks a given string around matches of the given regular expression. For Example: Input String: 016-78967 Regular Expression: – Output : {“016″,”78967”} Following are the two variants of split() method in Java: 1. Public String [ ] split ( String regex, int limit ) Parameters: regex – a delimiting regular expression… Read More »

SortedSet Interface in Java with Examples

SortedSet is an interface in collection framework. This interface extends Set and provides a total ordering of its elements. Exampled class that implements this interface is TreeSet. All elements of a SortedSet must implement the Comparable interface (or be accepted by the specified Comparator) and all such elements must be mutually comparable (i.e, Mutually Comparable… Read More »

How to remove an element from ArrayList in Java?

There are two way to remove an element from ArrayList. 1. By using remove() methods : ArrayList provides two overloaded remove() method. a. remove(int index) : Accept index of object to be removed. b. remove(Obejct obj) : Accept object to be removed. What happens when we have an integer arrayList and we want to remove… Read More »

Chained Exceptions in Java

Chained Exceptions allows to relate one exception with another exception, i.e one exception describes cause of another exception. For example, consider a situation in which a method throws an ArithmeticException because of an attempt to divide by zero but the actual cause of exception was an I/O error which caused the divisor to be zero.… Read More »

LinkedHashSet class in Java with Examples

A LinkedHashSet is an ordered version of HashSet that maintains a doubly-linked List across all elements. When the iteration order is needed to be maintained this class in used. When iterating through a HashSet the order is unpredictable, while a LinkedHashSet lets us iterate through the elements in the order in which they were inserted.when… Read More »

List Interface in Java with Examples

Java.util.List is a child interface of Collection. List is an ordered collection of objects in which duplicate values can be stored. Since List preserves the insertion order it allows positional access and insertion of elements. List Interface is implemented by ArrayList, LinkedList, Vector and Stack classes. Creating List Objects: List is an interface, we can… Read More »