我想使用java集合框架编写控制台应用程序,并使用eclipse编写OOPS。请指导我应该如何开始和一些样本代码,可能是有用的。提前感谢
发布于 2016-08-15 07:12:39
在Eclipse中创建新的Java应用程序。
然后在类的静态main()方法中:
//To add objects in a Collection, in this case Strings
ArrayList<String> strings = new ArrayList<String>();
strings.add("Michael");
strings.add("Jennifer");
//To show these objects in the Console
foreach(String string : strings){
System.out.println(string);
}这将创建包含字符串对象的列表,并在控制台上打印这些对象。您的集合可以包含任何类型的对象,不仅限于字符串,例如ArrayList<SomeClass>或ArrayList<Integer>
https://stackoverflow.com/questions/38950608
复制相似问题