我对Java编程还是很陌生,我正在try 使用以下代码更新现有值ArrayList
:
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add( "Zero" );
list.add( "One" );
list.add( "Two" );
list.add( "Three" );
list.add( 2, "New" ); // add at 2nd index
System.out.println(list);
}
我想打印New
而不是Two
,但结果是[Zero, One, New, Two, Three]
,我仍然有Two
.我想打印[Zero, One, New, Three]
.我该怎么做?