for構文でjava.util.ArrayListの要素を取り出す
1.Java構文
package zhongg;
import java.util.ArrayList;
public class ListDispEle {
public static void main(String[] args) {
ArrayList<String> userName= new ArrayList<>();
userName.add(“yamada");
userName.add(“sugimoto");
userName.add(“iihara");
userName.add(“taro");
for (int i = 0; i < userName.size(); i++) {
System.out.println(userName.get(i));
}
}
}
2.結果
yamada
sugimoto
iihara
taro