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 is a private class in java?
What do you understand by Header linked List?
What are the legal parameters?
Which sorting algorithm is in place?
What are local variables?
What is the format specifier?
What is a method signature java?
What is args length in java?
Which is fastest collection in java?
what are the methods in object?
What is the size of int in 64-bit jvm?
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.
What is the base class of all classes?
How can we find the actual size of an object on the heap?
How to obtain a performance profile of java program