[Practice] ArrayList


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

Recommended Posts

[Practice] ArrayList
[Practice] ArrayList
ArrayList practice
ArrayList
Array practice
Array practice 2
[Practice] Enumeration
ArrayList class
if else practice
String Buffer practice
LinkedList and ArrayList
java practice part 1
[Practice] Map method