All the strings through the collection JAVA

All the strings through the collection objects

public class ArrayListEach {
	public static void main(String[] args) {
		ArrayList<String> list = new ArrayList();
		
		//添加:add
		list.add("1");
		list.add("a");
		list.add("b");

		System.out.println(list); //[]

		// 遍历输出每一个字符串对象
		for (int i = 0; i < list.size(); i++) {
			//获取当前元素:get(int)
			String name = list.get(i);
			System.out.println(name);
		}
	}
}
Published 52 original articles · won praise 6 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_43472877/article/details/104103716