Discuss / Java / Arrays.asList 返回的是可以修改的List对象。虽然是Arrays内部的。

Arrays.asList 返回的是可以修改的List对象。虽然是Arrays内部的。

Topic source

[1, 2, 3, 4]

[1, 2, 33, 4]

List<String> stringList = new ArrayList<>();stringList.add("1");stringList.add("2");stringList.add("3");stringList.add("4");System.out.println(stringList.toString());Object [] strArr = stringList.toArray();String[] strArr2 = stringList.toArray(new String[stringList.size()]);List<String> stringList1 = Arrays.asList(strArr2);stringList1.set(2,"33");System.out.println(stringList1.toString());

基于jdk1.8,格式真是有毒,廖大神得修复修复了

List<String> stringList = new ArrayList<>();stringList.add("1");stringList.add("2");stringList.add("3");stringList.add("4");System.out.println(stringList.toString());Object [] strArr = stringList.toArray();String[] strArr2 = stringList.toArray(new String[stringList.size()]);List<String> stringList1 = Arrays.asList(strArr2);stringList1.set(2,"33");System.out.println(stringList1.toString());

List<String> stringList = new ArrayList<>();
stringList.add("1");
stringList.add("2");
stringList.add("3");
stringList.add("4");

System.out.println(stringList.toString());

Object [] strArr = stringList.toArray();
String[] strArr2 = stringList.toArray(new String[stringList.size()]);
List<String> stringList1 = Arrays.asList(strArr2);
stringList1.set(2,"33");
System.out.println(stringList1.toString());


  • 1

Reply