package arraylist;
import java.util.ArrayList;
import java.util.Iterator;
public class GetSetMethod {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Integer> ar1 = new ArrayList<Integer>(2);
ar1.add(1);
ar1.add(2);
ar1.add(3);
ar1.add(4);
ar1.add(5);
System.out.print("All value: ");
Iterator it1 = ar1.iterator();
while(it1.hasNext())
{
System.out.print(it1.next()+", ");
}
System.out.print("\n Setting value 8 to position 3: ");
ar1.set(2, 8);
Iterator it2 = ar1.iterator();
while(it2.hasNext())
{
System.out.print(it2.next()+", ");
}
System.out.print("\n Getting value of position 4: ");
System.out.print(ar1.get(3));
}
}
No comments:
Post a Comment