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
please send me hr interview questions in it industry
What is an empty class? What functionality does it offer in Java?
Can we declare array without size in java?
how would you implement a thread pool? : Java thread
What is this () in java?
what is optional in java 8?
Can you change array size in java?
Why is stringbuffer thread safe?
What are the 7 types of characters?
What is immutable class in java?
Explain restrictions for using anonymous inner classes?
What are different exception types exceptions available in java ?
Can you explain the meaning of aggregation and composition
What do you mean by stream pipelining in java 8?
What are the ways to instantiate the class class?