Q) I have a ArrayList object, in that object i have added 5
integer values, 5 float values, 5 string values. Now
question is how can delete particular type of data ( i.e all
int values or all float values or string values) in that
list object at a time?
Answer Posted / anjan singh
ArrayList al=new ArrayList();
al.add("a");al.add("b");al.add(1);al.add
(2);al.add(1.1);al.add(2.1);
System.out.println("Before:\n");
System.out.println(al);
for(int i=0;i<al.size();)
{
if(al.get(i) instanceof String)
al.remove(i);
else
i++;
}
System.out.println("After:\n");
System.out.println(al);
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What are JVM.JRE, J2EE, JNI?
Explain the difference between transient and volatile in java?
What is the difference between variable & constant?
what is interface in java? Explain
What is the maximum size of byte array in java?
Can you use abstract and final both with a method?
What is difference between == equals () and compareto () method?
What is data and its types?
What is meant by JVM? Is JVM platform independent or not?
is it possible to instantiate the math class?
What is dynamic binding(late binding)?
Explain the differences between static and dynamic variables?
What do you understand by an io stream?
Can we extend singleton class?
How does thread synchronization occurs inside a monitor?