ArrayList Modification Java Example

ArrayList Modification:

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);
		}
	}
}

Output:

ArrayList Values: 

Sachin
Gambhir
Dhoni
Sehwag
Raina
Yuvraj

ArrayList Values After Modification: 

Sachin
Dhawan
Dhoni
R.Sharma
Raina
Yuvraj

Recommended Books:

527 total views, 1 views today

About: Mirthbees

Blogger, Innovator, Developer and Enterpreneur. Founder of GuruRecharge, Readymade online recharge script. Lead Developer in Bookrate.in