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 / qim2010
The final Output is
size :4
Size after:2
While called ArrayList.remove() method, in remove method, we
can pass object or index number to remove.
// remove array list element by index number
list.remove(2); //will remove the second element
// remove ArrayList element by Object value
list.remove("2"); //will remove the element
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
design an lru cache in java?
What is <> used for in java?
What does java stand for?
What is string in java?
What is the exact difference in between Unicast and Multicast object?
What do you mean by stream pipelining in java 8?
Does java isempty check for null?
What is a loop java?
What is definition and declaration?
What is difference between hashset and hashmap?
What is the use of arraylist class in java?
How does indexof work?
Can java program run without jre?
How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters?
Write code to implement bubble sort in java?