1.
List Methods with Examples
Method: add(element)
List<String> fruits = new ArrayList<>();
[Link]("Apple");
[Link]("Banana");
[Link](fruits); // [Apple, Banana]
Method: get(index)
String fruit = [Link](0); // Apple
Method: set(index, element)
[Link](1, "Mango"); [Link](fruits);
// [Apple, Mango] Method: remove(index/object)
[Link]("Apple");
[Link](fruits); // [Mango]
Method: contains(object)
[Link]([Link]("Mango")); // true
Method: isEmpty()
[Link]([Link]()); // false
Method: clear()
[Link]();
[Link](fruits); // []
Real Example: Maintain Cart Items in Order
List<String> cart = new ArrayList<>();
[Link]("Shirt");
[Link]("Jeans");
[Link]("Shoes");
[Link]("Items in Cart: " + cart);
2.Set Methods with Examples
Method: add(element)
Set<Integer> numbers = new HashSet<>();
[Link](10);
[Link](20);
[Link](10); // Duplicate ignored
[Link](numbers); // [10, 20]
Method: contains(object)
[Link]([Link](20)); // true
Method: remove(object)
[Link](10);
[Link](numbers); // [20]
Method: isEmpty(), clear(), size()
[Link]([Link]()); // false
[Link]([Link]()); // 1
[Link]();
Real Example: Store Unique Voter IDs
Set<String> voterIds = new HashSet<>();
[Link]("VOTER123");
[Link]("VOTER456");
[Link]("VOTER123"); // Duplicate won't be added
[Link](voterIds);
3.Map Methods with Examples
Method: put(key, value)
Map<String, String> countryCapital = new HashMap<>();
[Link]("India", "Delhi"); [Link]("USA",
"Washington DC");
Method: get(key)
[Link]([Link]("India")); // Delhi
Method: containsKey(key), containsValue(value)
[Link]([Link]("USA")); // true
[Link]([Link]("Delhi")); // true Method:
keySet(), values(), entrySet()
[Link]([Link]()); // [India, USA]
[Link]([Link]()); // [Delhi, Washington DC]
[Link]([Link]()); // [India=Delhi, USA=Washington DC]
Method: remove(key)
[Link]("USA");
Real Example: Storing Student Marks
Map<String, Integer> studentMarks = new HashMap<>();
[Link]("Suresh", 85);
[Link]("Ramesh", 92);
[Link]("Marks of Ramesh: " + [Link]("Ramesh"));