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 extraneous variables examples?
Does java map allow duplicates?
Is a char always 1 byte?
What do heavy weight components mean in java programming?
What is == and === in javascript?
Is it safe to install java on my computer?
Differentiate between static and non-static methods in java.
What is return in java?
What are the advantages and disadvantages of object cloning?
What is the scope or life time of instance variables?
How do you compare arrays in java?
How does arraylist work in java?
What are JVM.JRE, J2EE, JNI?
What is a flag value?
When throws keyword is used?