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


Please Help Members By Posting Answers For Below Questions

What are JVM.JRE, J2EE, JNI?

701


Explain the difference between transient and volatile in java?

582


What is the difference between variable & constant?

549


what is interface in java? Explain

539


What is the maximum size of byte array in java?

544






Can you use abstract and final both with a method?

577


What is difference between == equals () and compareto () method?

537


What is data and its types?

580


What is meant by JVM? Is JVM platform independent or not?

586


is it possible to instantiate the math class?

535


What is dynamic binding(late binding)?

600


Explain the differences between static and dynamic variables?

594


What do you understand by an io stream?

594


Can we extend singleton class?

535


How does thread synchronization occurs inside a monitor?

561