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
Write a program to print all permutations of string?
Why char array is favored over string for the storage of passwords?
Can we serialize arraylist in java?
What is the difference between hashmap and hashtable in java?
What is the protected method modifier?
Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?
What is java virtual machine? Explain
Is string is a data type?
Why java is object oriented?
What is unmodifiable collection in java?
Explain different types of thread priorities ?
What is meant by the value of a variable?
What is the difference between a loader and a compiler?
Does java arraylist maintain insertion order?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? Or extending thread class or implementing runnable interface. Which is better? : Java thread