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 is a private class in java?

501


What do you understand by Header linked List?

586


What are the legal parameters?

494


Which sorting algorithm is in place?

531


What are local variables?

583






What is the format specifier?

505


What is a method signature java?

562


What is args length in java?

650


Which is fastest collection in java?

555


what are the methods in object?

623


What is the size of int in 64-bit jvm?

544


Draw a UML class diagram for the code fragment given below: public class StringApplet extends Applet { private Label sampleString; private Button showTheString; private ButtonHandler bHandler; private FlowLayout layout; public StringApplet() { sampleString = new Label(" "); showTheString = new Button (" Show the String"); bHandler = new ButtonHandler(); layout = new FlowLayout(); showTheString.addActionListener(bHandler); setLayout(layout); add(sampleString); add(showTheString); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { samplestring.setText("Good Morning"); } } } Note: The methods need not be indicated on the diagram.

1576


What is the base class of all classes?

560


How can we find the actual size of an object on the heap?

796


How to obtain a performance profile of java program

536