"Exploring ArrayList Methods in Java: add(), get(), set(), remove() and more"

🧭 Day 15: Common ArrayList Methods in Java Today I explored useful methods in the ArrayList class — they make managing dynamic lists super easy and powerful. 💡 What I Learned Today add() → Adds an element to the list. get(index) → Returns the element at the given index. set(index, element) → Updates an element. remove(index) → Deletes an element. size() → Returns the total number of elements. clear() → Removes all elements. contains(value) → Checks if an element exists. isEmpty() → Checks if the list is empty. 🧩 Example Code import java.util.ArrayList; public class ArrayListMethods {   public static void main(String[] args) {     ArrayList<String> names = new ArrayList<>();     names.add("Raj");     names.add("Kumar");     names.add("Devi");     System.out.println("First name: " + names.get(0));     names.set(1, "Arun");     System.out.println("After update: " + names);     names.remove(2);     System.out.println("After remove: " + names);     System.out.println("Contains Raj? " + names.contains("Raj"));     System.out.println("Size: " + names.size());   } } 🗣️ Caption for LinkedIn 🚀 Day 15 – Mastering ArrayList Methods in Java Learned how add(), get(), set(), remove() and more make ArrayList dynamic and powerful. These methods help handle data collections smoothly and efficiently 💡 #Java #CoreJava #ArrayList #LearnJava #ProgrammingJourney

  • graphical user interface

To view or add a comment, sign in

Explore content categories