对于字符串的替换:
package six; import java.util.Arrays; public class Sixoneseven { public static void main(String[] args){ String arr[]=new String[]{"1","2","3","4"}; // for(int i=0;i<arr.length;i++){ // System.out.print(" "+arr[i]); // } for(String str:arr){ System.out.print(" "+str); } Arrays.fill(arr,2,3,"bb"); System.out.println(); for(String str2:arr){ System.out.print(" "+str2); } } }
运行结果如下: