0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【練習】ArrayList

Last updated at Posted at 2020-09-09

package Array_pra;

import java.util.ArrayList;
import java.util.Iterator;


public class Animals {



	public static void main(String[] args) {
		//まずはインスタンスをつくる
		ArrayList<String> Animal=new ArrayList<String>();
        //値をaddメソッドで追加
		Animal.add("ひつじ");
		Animal.add("ねこ");
		Animal.add("いぬ");
		Animal.add("きつね");
		Animal.add("りす");

		//Animalの要素数を出力
		System.out.println(Animal.size());


		//Animalの配列内が空っぽか否か
		System.out.println(Animal.isEmpty());

        //Animalのどこに"ひつじ"が入ってるか
		System.out.println(Animal.indexOf("ひつじ"));

        //Animalの中に入っている要素をひとつづつ取り出す
		Iterator <String> itAnimal=Animal.iterator();
		while(itAnimal.hasNext()){

			String aaa=itAnimal.next();

			System.out.println(aaa);
		}
	}


}


実行結果
5
false
0
ひつじ
ねこ
いぬ
きつね
りす

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?