String[] cc = {"a","b","c"};
List<String> cca = null;
for(int i = 0; i<3; i++){
cca = new ArrayList<String>();
cca.add("z");
cca.add(cc[i]);
输出是[z,c];我想输出[z,a,b,c],该怎么改?
------解决方案--------------------
- Java code
String[] cc = {"a","b","c"}; List<String> cca = null; cca = new ArrayList<String>(); cca.add("z"); for(int i = 0; i<3; i++){ cca.add(cc[i]); } System.out.println(cca) ;
------解决方案--------------------
String[] cc = {"a","b","c"};
List<String> cca = new ArrayList<String>();
for(int i = 0; i<3; i++){
cca.add("z");
cca.add(cc[i]);
------解决方案--------------------
- Java code
String[] cc = {"a","b","c"}; List<String> cca = new ArrayList<String>(); cca.add("z"); for(int i = 0; i<3; i++){ cca.add(cc[i]); }
------解决方案--------------------
- Java code
import java.util.ArrayList;import java.util.List;public class b {public static void main(String[] args) { String[] cc = {"a","b","c"}; List<String> cca = new ArrayList<String>(); cca.add("z"); for (int i = 0; i < cc.length; i++) { cca.add(cc[i]); } System.out.println(cca);}}