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 / ggpune

Output will be
size :4
Size after: 2

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is singleton a bad practice?

569


What is a parameter in simple terms?

550


What is java thread dump, how can we get java thread dump of a program?

561


What are the new features in java 8? Explain

553


Explain about wait() method?

560






Is char a method in java?

508


How would you use Bubble Sort to sort the number of elements?

574


What is a instance variable in java?

541


Will the compiler creates a default constructor if I have a parameterized constructor in the class?

579


Give us the name of the list layoutmanagers in java?

517


What is overriding in java?

513


Explain the difference between association, aggregation and inheritance relationships.

549


Can we define package statement after import statement in java?

552


Difference between arraylist and hashset in java?

534


What is formatted output?

504