In this post we will see how to add elements in LinkedList. Elements can be added to LinkedList either using add(E e) which adds elements at the end of the list OR [crayon
ArrayList clear Vs removeAll
ArrayList can be emptied or cleared using either clear or removeAll method. Both these methods differ in performance. If you see the code for both these methods you will get to know which method is
How to clear Arraylist in java
To clear ArrayList in java we have 2 ways 1. void clear() – Clears all the elements that are present in the ArrayList 2. boolean removeAll(Collection<?> c) – Remov
How to clear Hashmap in java
To clear HashMap in java we use the void clear() method from Map. Using the clear method will empty the HashMap. Lets see examples on how to clear Hashmap in java. Example : C
How to get size of HashMap
To get size of HashMap we use the int size() method provided by Map API. The size method returns the number of key/value pairs that are available in that Map. Example : Get
How to Check if value exists in HashMap
To check if Value exists in HashMap, we use the containsValue(Object key) method provided by HashMap. boolean containsValue(Object key) searches the HashMap for the given value and returns
How to Check if key exists in HashMap
To check if Key exists in HashMap, we use the containsKey(Object key) method provided by HashMap. boolean containsKey(Object key) searches the HashMap for the given key and returns boole
How to remove elements from HashMap
To remove elements from HashMap we can use either of the 2 ways 1. Use the remove(Object key) method 2. Remove elements while iterating the HashMap Lets see some examples for both these ways 1. Use
How to add elements in HashMap (Key/Value)
To add elements in HashMap we use V Map.put(K key, V value) method. Elements in Hashmap are added in a Key/Value pair. Points to Remember about put() method 1. put() method maps the given
How to convert HashSet to ArrayList
In this post we will see examples to convert HashSet to ArrayList in java. HashSet and ArrayList are both Collection objects. Hence we can pass HashSet to the construtor of the ArrayList and get it