- /*
- * Arrays类的asList()方法:将数组转换为集合
- * 获取的集合:不能添加,不能删除;可以修改元素;
- *
- */
- public class Demo {
- public static void main(String[] args) {
- List<String> strList = Arrays.asList("张三","李四","王五","周六");
- List<Integer> intList = Arrays.asList(10,2,34,2,5,4,34,2);
-
- System.out.println("strList = " + strList.getClass().getName());
-
-
- for(String s : strList){
- System.out.println(s);
- }
-
- //添加一个元素
- // strList.add("赵七");//不能添加;运行时异常;
- // strList.remove(0);//不能删除元素;运行时异常;
- strList.set(0, " ");//可以修改元素;
- System.out.println("集合:" + strList);
-
-
-
- }
- }
复制代码 |
|