Karthikeya Boyini has Published 2383 Articles

Remove value from HashMap in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

644 Views

Use the remove() method to remove value from HashMap.First, create a HashMap and add elements −HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200));Now, remove a value, let’s say with key “Wallet” −Object ob = hm.remove("Wallet");The following is an example to remove a value from ... Read More

Add an element to specified index of ArrayList in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

442 Views

An element can be added to the specified index of an ArrayList by using the java.util.ArrayList.add() method. This method has two parameters i.e. the specific index at which to insert the element in the ArrayList and the element itself. If there is an element already present at the index specified ... Read More

Find minimum element of HashSet in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

2K+ Views

To get the minimum element of HashSet, use the Collections.min() method.Declare the HashSet −Set hs = new HashSet();Now let us add the elements −hs.add(29); hs.add(879); hs.add(88); hs.add(788); hs.add(456);Let us now get the minimum element −Object obj = Collections.min(hs);The following is an example to find the minimum element of HashSet −Example Live ... Read More

NavigableMap put() Method in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

76 Views

The NavigableMap put() method is used to set a specific key and value in the NavigableMap.The following is an example to implement NavigableMap put() method −Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { NavigableMap n = ... Read More

Get Synchronized Set from HashSet in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

262 Views

The synchronizedSet() method returns a synchronized (thread-safe) sorted set backed by the specified sorted set.First, create a HashSet and add elements −Set hs = new HashSet(); hs.add(29); hs.add(879); hs.add(88); hs.add(788); hs.add(456);Now, to get synchronized set, use the synchronizedSet() method −Set s = Collections.synchronizedSet(hs);The following is an example to get synchronized ... Read More

NavigableSet Class floor() method in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

87 Views

The floor() method returns the greatest element less than or equal to the given element i.e. 30 here −floor(30)The following is an example to implement the floor method in Java −Example Live Demoimport java.util.NavigableSet; import java.util.TreeSet; public class Demo { public static void main(String[] args) { ... Read More

Get higher key from NavigableMap in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

89 Views

Getting higher key means to return the least key strictly greater than the given key. This is done using higherKey() method in Java.The following is an example.Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { NavigableMap n ... Read More

Sort HashMap based on keys in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

175 Views

Firstly, create a HashMap −HashMap hm = new HashMap();Add some elements to the HashMap −hm.put("Shirts", new Integer(700)); hm.put("Trousers", new Integer(600)); hm.put("Jeans", new Integer(1200)); hm.put("Android TV", new Integer(450)); hm.put("Air Purifiers", new Integer(300)); hm.put("Food Processors", new Integer(950));Now, sort the HashMap based on keys using TreeMap −Map sort = new TreeMap(hm); System.out.println("Sorted Map ... Read More

NavigableMap ceilingEntry() method in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

72 Views

Use the NavigableMap ceilingEntry() method to returna key-value mapping associated with the least key greater than or equal to the given keyThe following is an example to implement ceilingEntry() method −Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { ... Read More

Remove specified element from Java LinkedHashSet

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:24

504 Views

To remove a specified element from LinkedHashSet, use the remove() and include the element you want to remove as a parameter.First, set LinkedHashSet and add elements −LinkedHashSet hashSet = new LinkedHashSet(); hashSet.add(10); hashSet.add(20); hashSet.add(30); hashSet.add(40); hashSet.add(50); hashSet.add(60);Let us now remove an element −hashSet.remove(10);The following is an example to remove specified ... Read More

Advertisements