DEV Community

Harsha S
Harsha S

Posted on

Day 22 Arraylists in Java

Importing it

import java.util.ArrayList;

Initializing it

ArrayList< String > Names = new ArrayList<>();

Adding Values

Names.add("Harsha");
Names.add(1,"Your_name");

Removing Values

Names.remove(0);
Names.remove("Harsha");

Getting Values

Names.get(0);

Checking If A Value Exists

Names.contains("Your_name");

Finding The Index

Names.indexOf("Your_name");

Updating a Value

Names.set(0,"You);

Checking The Size

Names.size();

Sorting the List

Collections.sort(Names);

Top comments (0)