package Array_pra;
import java.util.ArrayList;
import java.util.Iterator;
public class Animals {
public static void main(String[] args) {
//First, create an instance
ArrayList<String> Animal=new ArrayList<String>();
//Add value with add method
Animal.add("sheep");
Animal.add("Cat");
Animal.add("Dog");
Animal.add("Fox");
Animal.add("Risu");
//Output the number of elements of Animal
System.out.println(Animal.size());
//Whether the Animal array is empty
System.out.println(Animal.isEmpty());
//Where in Animal"sheep"Is there
System.out.println(Animal.indexOf("sheep"));
//Take out the elements contained in Animal one by one
Iterator <String> itAnimal=Animal.iterator();
while(itAnimal.hasNext()){
String aaa=itAnimal.next();
System.out.println(aaa);
}
}
}
Execution result 5 false 0 sheep Cat Dog Fox Risu