如何在Java中替换ArrayList元素的现有值
我对Java编程仍然很陌生,我正在尝试使用此代码更新a的现有值: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]