How to replace existing value of ArrayList element in java -


i still quite new java programming , trying update existing value of array list using code

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 @ 2nd index       system.out.println(list);} 

i want print new instead of tow got [zero, one, new, two, three] result, still have "two". want print [zero, one, new, three]. how do this? thank you..

use set method replace old value new one.

list.set( 2, "new" ); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -