ArrayList Modification Java Example

ArrayList Modification:

[java highlight=”23,24″]
package in.javadomain;

import java.util.ArrayList;
import java.util.ListIterator;

public class ReverseIteration {

public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("Sachin");
list.add("Gambhir");
list.add("Dhoni");
list.add("Sehwag");
list.add("Raina");
list.add("Yuvraj");
ListIterator<String> li = list.listIterator();
System.out.println("ArrayList Values: \n");
for (String val : list) {
System.out.println(val);
}

System.out.println("\nArrayList Values After Modification: \n");
list.set(1, "Dhawan");
list.set(3, "R.Sharma");

for (String val : list) {
System.out.println(val);
}
}
}
[/java]

Output:
[plain gutter=”false”]
ArrayList Values:

Sachin
Gambhir
Dhoni
Sehwag
Raina
Yuvraj

ArrayList Values After Modification:

Sachin
Dhawan
Dhoni
R.Sharma
Raina
Yuvraj
[/plain]

Recommended Books:

Leave a Reply