Samual Sam has Published 2310 Articles

Barrier Objects in Python

Samual Sam

Samual Sam

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

506 Views

Barrier provides one of the python synchronization technique with which single or multiple threads wait until a point in a set of activities and make progress together.To define a barrier object, “threading. Barrier” is used.threading.Barrier(parties, action = None, timeout = None)Where, parties = Number of threadsaction = called by one ... Read More

Get Tail Map from TreeMap in Java

Samual Sam

Samual Sam

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

182 Views

To get Tail Map from TreeMap, use the tailMap() method. It gets a part or view of the map whose keys are greater than equal to the key set as a parameter.Let us first create a TreeMap −TreeMap m = new TreeMap();Now, we will add some elements −m.put(1, "PHP"); m.put(2, ... Read More

NavigableMap floorEntry() method in Java

Samual Sam

Samual Sam

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

204 Views

The floorEntry() NavigableMap method returns a key-value mapping associated with the greatest key less than or equal to the given keyThe following is an example to implement floorEntry() method −Example Live Demoimport java.util.*; public class Demo {    public static void main(String[] args) {       NavigableMap n = new ... Read More

Display HashMap elements in Java

Samual Sam

Samual Sam

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

594 Views

Create a HashMap −HashMap hm = new HashMap();Add elements to the HashMap that we will be displaying afterward −hm.put("Maths", new Integer(98)); hm.put("Science", new Integer(90)); hm.put("English", new Integer(97)); hm.put("Physics", new Integer(91));Now, to display the HashMap elements, use Iterator. The following is an example to display HashMap elements −Example Live Demoimport java.util.*; public ... Read More

Check if a HashMap is empty in Java

Samual Sam

Samual Sam

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

636 Views

Use the isEmpty() method to check of a HashMap is empty or not. Let us first create the HashMap −HashMap hm = new HashMap();Now, add some elements −hm.put("Bag", new Integer(1100)); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600));Since, we added elements above, therefore, the HashMap isn’t empty. Let us check −set.isEmpty()The following ... Read More

Use ListIterator to traverse an ArrayList in the reverse direction in Java

Samual Sam

Samual Sam

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

2K+ Views

A ListIterator can be used to traverse the elements in the forward direction as well as the reverse direction in the List Collection. So the ListIterator is only valid for classes such as LinkedList, ArrayList etc.The method hasPrevious( ) in ListIterator returns true if there are more elements in the ... Read More

Fill elements in a Java float array in a specified range

Samual Sam

Samual Sam

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

181 Views

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

Iterate through the values of Java LinkedHashMap in Java

Samual Sam

Samual Sam

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

1K+ Views

An iterator is used in Java to iterate through the values of LinkedHashMap.Let us first create LinkedHashMap −LinkedHashMap l = new LinkedHashMap();Add some elements to the 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");Iterate through the values −Collection res = l.values(); Iterator i = res.iterator(); ... Read More

Check whether a HashSet is empty or not in Java

Samual Sam

Samual Sam

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

1K+ Views

To check whether a HashSet is empty or not, use the isEmpty() method.Create a HashSet −HashSet hs = new HashSet();Add elements to the HashSet −hs.add("B"); hs.add("A"); hs.add("D"); hs.add("E"); hs.add("C"); hs.add("F"); hs.add("K"); hs.add("M"); hs.add("N");Now, check whether the HashSet is empty or not. Since we added elements above, it won’t be empty ... Read More

Check whether two HashSet are equal in Java

Samual Sam

Samual Sam

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

424 Views

At first, create the first HashSet and add elements to it −// create hash set 1 HashSet hs1 = new HashSet(); hs1.add("G"); hs1.add("H"); hs1.add("I"); hs1.add("J"); hs1.add("K");Create the second HashSet and add elements to it −// create hash set 2 HashSet hs2 = new HashSet(); hs2.add("G"); hs2.add("H"); hs2.add("I"); hs2.add("J"); hs2.add("K");To check ... Read More

Advertisements