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 the important features of Java 10 release?
How do you create a sop?
What is the difference between a constructor and a method?
Why is singleton not thread safe?
What Is Query Throttling in java?
What are "methods" and "fields"?
Can a list be null in java?
Difference between error and exception
What is the purpose of extern variable?
What is overriding in java?
What is the formula to calculate percentage?
what type of questions asked for barclays technologies pune please send urgent
What are the steps involved to create a bean?
What is double checked locking in singleton?
What do you mean by an interface in java?