? Java Collections PDF – All Methods and Use Cases
? Java Collections PDF – All Methods and Use Cases
Method: add(element)
Method: get(index)
fruits.remove("Apple");
System.out.println(fruits); // [Mango]
Method: contains(object)
System.out.println(fruits.contains("Mango")); // true
Method: isEmpty()
System.out.println(fruits.isEmpty()); // false
Method: clear()
fruits.clear();
System.out.println(fruits); // []
Method: add(element)
System.out.println(numbers.contains(20)); // true
Method: remove(object)
numbers.remove(10);
System.out.println(numbers); // [20]
Method: isEmpty(), clear(), size()
System.out.println(numbers.isEmpty()); // false
System.out.println(numbers.size()); // 1
numbers.clear();
Method: get(key)
System.out.println(countryCapital.get("India")); // Delhi
System.out.println(countryCapital.containsKey("USA")); // true
System.out.println(countryCapital.containsValue("Delhi")); // true Method:
countryCapital.remove("USA");
Real Example: Storing Student Marks
studentMarks.put("Ramesh", 92);
System.out.println("Marks of Ramesh: " + studentMarks.get("Ramesh"));