What will be the output of the program?

public class Test {
public static void main(String args[]) {
ArrayList<String> list = new ArrayList<String>();
list.add("2");
list.add("3");

list.add("4");
list.add("5");
System.out.println("size :"+list.size());
for(int i=0;i<list.size();i++) {
list.remove(i);
}
System.out.println("size after:"+list.size());
}
}

Answer Posted / surendrababu koppula

ArrayList class remove method example.remove(int index) Removes the element at the specified position in this list. Shifts any subsequent elements to the left.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an object in java and how is it created?

593


why using interface interface ?

1516


When is finally block not called?

586


When we should use serialization?

576


What is data movement?

669






Why pass by reference is not possible in java?

506


Give a brief description of java socket programming?

536


What is local declaration?

497


How to read and write image from a file ?

563


What is the difference between a factory and abstract factory pattern?

689


What is bytecode verifier?

514


Who developed java?

584


What are the features in java?

582


Are static members inherited to sub classes?

648


take an array with -ve and +ve value both.find out the nearest value of 0(zero).if two values are same like(-2 and +2)then extract +2 is nearest of 0(zero).

1537