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 are the important features of Java 11 release?

572


What is meant by anonymous class?

585


How do I get 64 bit java?

517


What is externalizable?

609


What is the main difference between java platform and other platforms?

498






How java is similar to c?

582


Class c implements interface I containing method m1 and m2 declarations. Class c has provided implementation for method m2. Can I create an object of class c?

1012


What types of index data structures can you have in java?

606


What is JVM and is it platform independent?

555


What are loops in java? What are three types of loops?

544


What does int argc char * argv [] mean?

507


What is a file pointer?

509


What is rule of accessibility in java?

537


When a thread is executing synchronized methods , then is it possible to execute other synchronized methods simultaneously by other threads?

559


How do you classify Dialog Box?

639