When we are working with ArrayList of Objects then it is must that we have to override toString() method of Java ArrayList to get the output in the desired format. Lets learn how to override toString() method. … [Read more...]
Find Common Elements between two ArrayList in Java
In this tutorial we will learn how to get the common elements between two ArrayList. We would be using removeAll() method to retain only the common elements between two lists. public boolean removeAll(Collection<?> c) It removes all the elements in the list that are not contained in the specified list. … [Read more...]
Java TreeMap values() Method Example
The values() method of java.util.TreeMap class returns a Collection view of the values contained in this map. The collection's iterator returns the values in ascending order of the corresponding keys. … [Read more...]
Java TreeMap floorKey() Method Example
The floorEntry() method of java.util.TreeMap class returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key. whereas floorKey() method returns the greatest key less than or equal to the given key, or null if there is no such key. … [Read more...]
Java TreeMap ceilingEntry(K key) Example
The ceilingEntry(K key) method of java.util.TreeMap class returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key. … [Read more...]
Java HashMap putAll(Map extends K,? extends V> m) Example
The put(K key, V value) method of java.util.HashMap class associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced whereas putAll(Map<? extends K,? extends V> m) method copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this … [Read more...]
Java HashMap entrySet() Example
The entrySet() method of java.util.HashMap class returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. … [Read more...]
Java HashMap containsValue(Object value) Example
The containsKey(Object key) method of java.util.HashMap class returns true if this map contains a mapping for the specified key where as containsValue(Object value) method returns true if this map maps one or more keys to the specified value. … [Read more...]
Java TreeSet descendingSet() Method Example
The descendingIterator() method of java.util.TreeSet class will return an iterator over the elements in this set in descending order whereas descendingSet() method returns a reverse order view of the elements contained in this set. The descending set is backed by this set, so changes to the set are reflected in the descending set, and vice-versa. If either set is modified while … [Read more...]
Java Vector toString() Example
The toString() method of java.util.Vector class returns a string representation of the Vector, containing the String representation of each element. … [Read more...]
Java Vector size() Example
The size() method of java.util.Vector class will return us the actual size of the vector(Count of number of elements present in the vector). … [Read more...]
Java LinkedHashSet add(E e) Method Example
In this tutorial we will learn about add(E e) method of java.util.LinkedHashSet class. This method inserts the specified element to the end of the LinkedHashSet … [Read more...]