// Java program to populate and update a LinkedList
import java.util.LinkedList;
class LinkList {
// The driver method
public static void main( String[ ] args ) {
LinkedList<Integer> numbers = new LinkedList<>( );
int n = args.length;
int index = Integer.parseInt( args[n-2] );
int value = Integer.parseInt( args[n-1] );
// Add elements in the linked list.
for ( int i = 0; i < n-2; i++ )
numbers.( Integer.parseInt( args[i] ) );
System.out.println( "LinkedList: " + numbers );
// Change an element.
numbers.( index, value );
System.out.println( "Updated LinkedList: " + numbers );
}
}
|