不需要循环,直接替换指定位置的元素,局限是String数组不能有相同的元素.
public class Test002 {
public static void main(final String[] args) {
final String[] str = new String[]{"aaa","bbb","ccc"};
System.out.println(str[0]+","+str[1]+","+str[2]);
final List<String> list =Arrays.asList(str);
Collections.replaceAll(list, str[1], "123");//把bbb替换成123
final String[] str1=(String[])list.toArray();
System.out.println(str1[0]+","+str1[1]+","+str1[2]);
}
}