Karthikeya Boyini has Published 2192 Articles

Get the count of elements in HashMap in Java

karthikeya Boyini

karthikeya Boyini

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

14K+ Views

Use the size() method to get the count of elements.Let us first create a HashMap and add elements −HashMap hm = new HashMap(); // Put elements to the map hm.put("Maths", new Integer(98)); hm.put("Science", new Integer(90)); hm.put("English", new Integer(97));Now, get the size −hm.size()The following is an example to get the count ... Read More

Socket Programming with Multi-threading in Python?

karthikeya Boyini

karthikeya Boyini

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

5K+ Views

Multithreading ConceptsMultithreading is the core concept of nearly all modern programming languages especially python because of its simplistic implementation of threads.A thread is a sub-program within a program that can be executed independently of other section of the code. A thread executes in the same context sharing program’s runnable resources ... Read More

Iterate through the values of TreeMap in Java

karthikeya Boyini

karthikeya Boyini

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

739 Views

Use Iterator and the values() method to iterate through the values of TreeMap.Let us first create a TreeMap 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");Iterate through the values −Collection res = m.values(); Iterator i ... Read More

NavigableMap pollLastEntry() method in Java

karthikeya Boyini

karthikeya Boyini

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

96 Views

The NavigableMap pollLastEntry() method remove and returns a key-value mapping associated with the greatest key in this map.Let us first create a NavigableMap and add some elements to it −NavigableMap n = new TreeMap(); n.put(5, "Tom"); n.put(9, "John"); n.put(14, "Jamie"); n.put(1, "Tim"); n.put(4, "Jackie"); n.put(15, "Kurt"); n.put(19, "Tiger"); n.put(24, "Jacob");Now, ... Read More

Fill elements in a Java byte array in a specified range

karthikeya Boyini

karthikeya Boyini

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

562 Views

Elements can be filled in a Java byte array in a specified range using the java.util.Arrays.fill() method. This method assigns the required byte value in the specified range to the byte array in Java.The parameters required for the Arrays.fill() method are the array name, the index of the first element ... Read More

Get Size of Java LinkedHashMap

karthikeya Boyini

karthikeya Boyini

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

677 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

251 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

294 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

377 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

276 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

Advertisements