Karthikeya Boyini has Published 2383 Articles

Get Size of Java LinkedHashMap

karthikeya Boyini

karthikeya Boyini

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

454 Views

The size() method is used to get the size of LinkedHashMap in Java.Create a LinkedHashMap and add some elements to it −LinkedHashMap l = new LinkedHashMap(); l.put("1", "Jack"); l.put("2", "Tom"); l.put("3", "Jimmy"); l.put("4", "Morgan"); l.put("5", "Tim"); l.put("6", "Brad");Get the size now −l.size()The following is an example to get the size ... Read More

Find the size of a HashMap in Java

karthikeya Boyini

karthikeya Boyini

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

183 Views

Use the size() method to get the size of HashMap. Let us first create a HashMapHashMap hm = new HashMap();Now, add some elements −hm.put("Bag", new Integer(1100)); hm.put("Sunglasses", new Integer(2000)); hm.put("Franes", new Integer(800)); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600));Since, we added 5 elements above, therefore, the size() method will give 5 ... Read More

Check if a particular element exists in Java LinkedHashSet

karthikeya Boyini

karthikeya Boyini

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

184 Views

Use the contains() method to check if a specific element exists in LinkedHashSet or not.Let us first create a LinkedHashSet and add some elements −LinkedHashSet l = new LinkedHashSet(); l.add(new String("1")); l.add(new String("2")); l.add(new String("3")); l.add(new String("4")); l.add(new String("5")); l.add(new String("6")); l.add(new String("7"));Now, check whether it contains element “5” or ... Read More

Convert elements in a HashSet to an array in Java

karthikeya Boyini

karthikeya Boyini

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

274 Views

First, create a HashSet and elements to it −HashSet hs = new HashSet(); // add elements to the hash set hs.add("B"); hs.add("A"); hs.add("D"); hs.add("E"); hs.add("C"); hs.add("F"); hs.add("K");Let us now convert the above HashSet to an array −Object[] ob = hs.toArray();The following is an example to convert elements in a HashSet ... Read More

Convert a Set into a List in Java

karthikeya Boyini

karthikeya Boyini

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

198 Views

First, create a Set and add elements −Set s = new HashSet(); s.add("P"); s.add(new Date()); s.add(new Long(898999)); s.add("Q"); s.add("R"); s.add(new Integer(1));Convert the above Set to a List −List l = new ArrayList(s);The following is an example to convert a set into a list in Java −Example Live Demoimport java.util.ArrayList; import java.util.Date; ... Read More

Find maximum element of HashSet in Java

karthikeya Boyini

karthikeya Boyini

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

3K+ Views

To get the maximum element of HashSet, use the Collections.max() 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 maximum element −Object obj = Collections.max(hs);The following is an example to find maximum element of HashSet −Example Live Demoimport ... Read More

Fetch key-valuepair from Java LinkedHashSet

karthikeya Boyini

karthikeya Boyini

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

229 Views

To fetch LinkedHashSet key-value pair in Java, use the entrySet() method.Let us first create LinkedHashSet and add some elements −LinkedHashMap l = new LinkedHashMap(); l.put("1", "Jack"); l.put("2", "Tom"); l.put("3", "Jimmy"); l.put("4", "Morgan"); l.put("5", "Tim"); l.put("6", "Brad");Now, fetch a key-value pair −l.entrySet()The following is an example to fetch key-value pair from ... Read More

Java Program to check if a particular key exists in TreeMap

karthikeya Boyini

karthikeya Boyini

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

121 Views

To check if a particular key exists in TreeMap, use the containsKey() method.Create a TreeMap first and add some elements −TreeMap m = new TreeMap(); m.put(1, "PHP"); m.put(2, "jQuery"); m.put(3, "JavaScript"); m.put(4, "Ruby"); m.put(5, "Java"); m.put(6, "AngularJS"); m.put(7, "ExpressJS");Now, let’s say we need to check that key 5 exists or ... Read More

Check if the File object refers to an absolute pathname in Java

karthikeya Boyini

karthikeya Boyini

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

301 Views

The method java.io.File.isAbsolute() is used to check if the file object refers to an absolute pathname. This method returns true if the abstract path name is absolute and false if the abstract path name is not absolute.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class ... Read More

Get the String representation of the current File object in Java

karthikeya Boyini

karthikeya Boyini

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

154 Views

The string representation of the current file object can be obtained using the method java.io.File.toString(). This method returns the abstract path name in the string form.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {     ... Read More

Advertisements