// The Collections framework is defined in the java.util package
import java.util.ArrayList;
class Main {
public static void main(String[] args){
ArrayList<String> animals = new ArrayList<>();
// Add elements
animals.add("Dog");
animals.add("Cat");
animals.add("Horse");
System.out.println("ArrayList: " + animals);
}
}
import java.util.List;
import java.util.ArrayList;
class Main {
public static void main(String[] args) {
// Creating list using the ArrayList class
List<String> list = new ArrayList<>();
// Add elements to the list
list.add("Apple");
list.add("Mango");
list.add("Banana");
System.out.println("List: " + list);
// Access element from the list
String str = list.get(1);
System.out.println("Accessed Element: " + str+"
");
// Remove element from the list
String removedstr = list.remove(1);
System.out.println("Removed Element: " + removedstr);
}
}