0% found this document useful (0 votes)
5 views

Array List Demo

Uploaded by

roshan.prajapati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Array List Demo

Uploaded by

roshan.prajapati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

ArrayList;

class ArrayListDemo {
public static void main(String[] args){
// create ArrayList
ArrayList<String> languages = new ArrayList<>();

// add() method without the index parameter


languages.add("Java");
languages.add("C");
languages.add("Python");
languages.add("CPP");
languages.add("Ruby");
System.out.println("ArrayList: " + languages);

// get the element from the arraylist


String str = languages.get(1);
System.out.print("Element at index 1: " + str);

// change the element of the array list


languages.set(2, "JavaScript");
System.out.println("Modified ArrayList: " + languages);

// remove element from index 2


String str = languages.remove(3);
System.out.println("Updated ArrayList: " + languages);
System.out.println("Removed Element: " + str);

}
}

You might also like