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
How to compare two strings in java program?
Why is a singleton bad?
How do you add an element to an arraylist in java?
Why do I need to declare the type of a variable in java?
Write an algorithm for quick sort?
In multi-threading how can we ensure that a resource isn't used by multiple threads simultaneously?
In java, how many ways you can take input from the console?
How many bits is a 64 bit byte?
Name the components that are termed to be Heavy-weight component but available in Light-weight components?
What is the difference between private & public & friendly classes?
What are the advantages of passing this into a method instead of the current class object itself?
How do you sort a string in java?
Which is faster set or list in java?
What is a text string?
How does thread synchronization occurs inside a monitor?