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
Explain java coding standards for variables ?
Why map is used in java?
What is try-with-resources in java?
What is polymorphism and what are the types of it?
What is abstract class constructor called?
What is data object example?
What is a numeric literal?
What are java packages? What is the significance of packages?
What is integer valueof?
What is the size of arraylist in java?
What is a protected method?
Differentiate between stringbuffer and string?
What happens when you invoke a thread’s interrupt method while it is sleeping or waiting?
How to calculate the length of a singly linked list in java?
Can we synchronize static methods in java?