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
How do you execute a thread in java?
What is thread pool? How can we create thread pool in java?
What is an example of a keyword?
What is functional interface in javatpoint?
What is the difference between super class & sub class?
How to sort elements in a parallel array in java?
Is alive in java?
What is the escape character in java?
How are this() and super() used with constructors in java programming?
Can we use a switch statement with strings?
What are the advantages of passing this into a method instead of the current class object itself?
Difference between == and .equals() ?
Why do we override tostring method in java?
What is starvation?
What is the use of generics? When was it added to the Java development Kit?