Java Collections.asLifoQueue() method

The java.util.Collections class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, “wrappers”, which return a new collection backed by a specified collection, and a few other odds and ends. Collections.asLifoQueue() method will returns a view of a Deque as a Last-in-first-out (Lifo) Queue. Syntax: … Read more

How to add all elements to the given collection object?

The java.util.Collections class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, “wrappers”, which return a new collection backed by a specified collection, and a few other odds and ends. Collections.addAll() method adds all of the specified elements to the specified collection. Syntax: public boolean … Read more

Java collections class

The java.util.Collections class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, “wrappers”, which return a new collection backed by a specified collection, and a few other odds and ends. Java Collections class fields static List EMPTY_LIST: This is the empty list (immutable). static Map … Read more

collection framework interview programs in java

Collection framework: Collection framework is a unified architecture or a set classes and interfaces for representing and manipulating collections. i.e. collection framework is used to store, retrieve and manipulate collections. Collection framework interview programs: How to Iterate collection objects How to Remove element from collection How to Read all elements in vector How to Copy or … Read more

Find user defined objects as a key from linkedhashmap

Example package com.w3spoint;   import java.util.LinkedHashMap;   class Employee{ private String name; private int salary; private int id;   public Employee(int id, String name, int salary){ this.id = id; this.name = name; this.salary = salary; }   public String getName() { return name; } public void setName(String name) { this.name = name; } public int … Read more

Eliminate duplicate user defined objects as a key from linkedhashmap

Example package com.w3spoint;   import java.util.LinkedHashMap;   class Employee{ private String name; private int salary; private int id;   public Employee(int id, String name, int salary){ this.id = id; this.name = name; this.salary = salary; }   public String getName() { return name; } public void setName(String name) { this.name = name; } public int … Read more

Remove all entries from linkedhashmap

We can use clear() method to remove all entries from linkedhashmap. clear(): Removes all key-value pairs from this map. Syntax: public void clear() Example package com.w3spoint;   import java.util.LinkedHashMap;   public class Test { public static void main(String args[]){ LinkedHashMap<Integer, String> linkedHashMap = new LinkedHashMap<Integer, String>();   //Add objects to the HashSet. linkedHashMap.put(4, "Roxy"); linkedHashMap.put(2, … Read more

Search a value in linkedhashmap in java

We can use containsValue() method to search a value in linkedhashmap in java. containsValue(Object v): Returns true if this map contains specified value otherwise returns false. Syntax: public boolean containsValue(Object v) Example package com.w3spoint;   import java.util.LinkedHashMap;   public class Test { public static void main(String args[]){ LinkedHashMap<Integer, String> linkedHashMap = new LinkedHashMap<Integer, String>();   … Read more

Search a key in linkedhashmap in java

We can use containsKey() method to search a key in treemap in java. containsKey(Object k): Returns true if this map contains specified key otherwise returns false. Syntax: public boolean containsKey(Object k) Example package com.w3spoint;   import java.util.LinkedHashMap;   public class Test { public static void main(String args[]){ LinkedHashMap<Integer, String> linkedHashMap = new LinkedHashMap<Integer, String>();   … Read more

Iterate linkedhashmap in java

Example package com.w3spoint;   import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set;   public class Test { public static void main(String args[]){ LinkedHashMap<Integer, String> linkedHashMap = new LinkedHashMap<Integer, String>();   //Add objects to the HashSet. linkedHashMap.put(4, "Roxy"); linkedHashMap.put(2, "Sunil"); linkedHashMap.put(5, "Sandy"); linkedHashMap.put(1, "Munish"); linkedHashMap.put(3, "Pardeep");   //Print the LinkedHashMap object. System.out.println("LinkedHashMap elements:"); System.out.println(linkedHashMap);   //Get … Read more