我有这个数组:
array = [null, p, ;, z,null, OR, y]
我想用任何其他值替换null值。我该怎么做?
答案 0 :(得分:1)
for (pos=0;pos<array.length;pos++) {
if(array[pos]==null) {
array[pos]=xyz
}
}
答案 1 :(得分:1)
喜欢这个
String[] values= {null,"p", ";","z",null, "OR","y"};
List<String> list=new ArrayList<String>(Arrays.asList(values));
Collections.replaceAll(list, null, "newVal");
values = list.toArray(new String[list.size()]);
System.out.println(Arrays.toString(values));