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
Difference between this() and super() in java ?
What are the different types of inheritance in java?
Can you tell me range of byte?
Can we use String with switch case?
hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea
What does serializing data mean?
How many bits is a string in java?
What do you mean by append?
What are the methods of object class ?
What is bytecode verifier?
What are the differences between abstract class and interface?
What is the core java?
What is getclass () getname () in java?
What Is Query Throttling in java?
What is tcp and udp?