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 two environment variables that must be set in order to run any java programs?
What is the default size of arraylist in java?
How do I type unicode?
How is string immutable in java?
What is meant by singleton class?
How is treeset implemented in java?
what is object-oriented programming in java?
What are the steps in the jdbc connection?
What is double parsedouble in java?
Explain about the dynamic behavior of core java?
List some features of the abstract class.
Tell me how many ways are there to initialise an integer with a constant.
What is lambda expression in java?
What will happen if static modifier is removed from the signature of the main method?
What is a vector in java?