Parrainage hello bank 100

Comment

Author: Admin | 2025-04-28

= new HashMap(); for (int i = 0; i Integer c = hmap.get(arr[i]); if (hmap.get(arr[i]) == null) { hmap.put(arr[i], 1); } else { hmap.put(arr[i], ++c); } } System.out.println(hmap); } public static void main(String[] args) { int arr[] = { 10, 34, 5, 10, 3, 5, 10 }; createHashMap(arr); }}Output{34=1, 3=1, 5=2, 10=3}With the help of LinkedHashMap (Similar to HashMap, but keeps order of elements)Javaimport java.util.*; public class BasicLinkedHashMap { public static void main(String a[]) { LinkedHashMap lhm = new LinkedHashMap(); lhm.put("one", "practice.geeksforgeeks.org"); lhm.put("two", "code.geeksforgeeks.org"); lhm.put("four", "www.geeksforgeeks.org"); System.out.println(lhm); System.out.println("Getting value for key 'one': " + lhm.get("one")); System.out.println("Size of the map: " + lhm.size()); System.out.println("Is map empty? " + lhm.isEmpty()); System.out.println("Contains key 'two'? "+ lhm.containsKey("two")); System.out.println("Contains value 'practice.geeks" +"forgeeks.org'? "+ lhm.containsValue("practice"+ ".geeksforgeeks.org")); System.out.println("delete element 'one': " + lhm.remove("one")); System.out.println(lhm); } } Output{one=practice.geeksforgeeks.org, two=code.geeksforgeeks.org, four=www.geeksforgeeks.org}Getting value for key 'one': practice.geeksforgeeks.orgSize of the map: 3Is map empty? falseContains key 'two'? trueContains value 'practice.geeksforgeeks.org'? truedelete element 'one': practice.geeksforgeeks.org{two=code.geeksforgeeks.org, four=www.geeksforgeeks.org}With the help of ConcurretHashMap(Similar to Hashtable, Synchronized, but faster as multiple locks are used)Javaimport java.util.concurrent.*;class ConcurrentHashMapDemo { public static void main(String[] args) { ConcurrentHashMap m = new ConcurrentHashMap(); m.put(100, "Hello"); m.put(101, "Geeks"); m.put(102, "Geeks"); System.out.println("ConcurrentHashMap: " + m); m.putIfAbsent(101, "Hello"); System.out.println("\nConcurrentHashMap: " + m); m.remove(101, "Geeks"); System.out.println("\nConcurrentHashMap: " + m); m.replace(100, "Hello", "For"); System.out.println("\nConcurrentHashMap: " + m); }}OutputConcurentHashMap: {100=Hello, 101=Geeks, 102=Geeks}ConcurentHashMap: {100=Hello, 101=Geeks, 102=Geeks}ConcurentHashMap: {100=Hello, 102=Geeks}ConcurentHashMap: {100=For, 102=Geeks}With the help of HashSet (Similar to HashMap, but maintains only keys, not pair)Javaimport java.util.*;class Test { public static void main(String[] args) { HashSet h = new HashSet(); h.add("India");

Add Comment