Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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?

Answers were Sorted based on User's Feedback



Q) I have a ArrayList object, in that object i have added 5 integer values, 5 float values, 5 strin..

Answer / srivatsava

import java.util.*;
public class ArrayListDeleteParticularDataTypeExample {

/**
* @param args
*/
public static void main(String[] args) {
ArrayListDeleteParticularDataTypeExample obj = new ArrayListDeleteParticularDataTypeExample();
ArrayList al = new ArrayList();
al.add(new Integer(1));
al.add(new Integer(2));
al.add(new Integer(3));
al.add("A");
al.add("B");
al.add("C");
al.add(new Float(10.10));
al.add(new Float(20.20));
al.add(new Float(30.30));
System.out.println("ArrayList Size Before - "+al.size());
System.out.println("ArrayList Values Before- "+al);
Iterator it = al.iterator();
while(it.hasNext()){

if(it.next() instanceof String){
it.remove();
}
}
System.out.println("ArrayList Size After - "+al.size());
System.out.println("ArrayList Values After - "+al);
}

}

Is This Answer Correct ?    8 Yes 0 No

Q) I have a ArrayList object, in that object i have added 5 integer values, 5 float values, 5 strin..

Answer / murli

for(int i=0;i<arr.size();i++){
if(arr.get(i) instanceof Integer)
arr.remove(i);
}

Is This Answer Correct ?    5 Yes 4 No

Q) I have a ArrayList object, in that object i have added 5 integer values, 5 float values, 5 strin..

Answer / 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

More Core Java Interview Questions

Name few java util classes introduced with java 8 ?

0 Answers  


what is synchronization? : Java thread

0 Answers  


What are inbuilt functions in java?

0 Answers  


How to sort the elements in HashMap

3 Answers   Ness Technologies,


What does I ++ mean?

0 Answers  


How to count occurrences of each duplicate element in a list {a,b,d,c,a,b} ? Thanks in Advance

2 Answers   TCS,


what is the use of custom tags? with example?

1 Answers   Photon,


What are the types of arrays in java?

0 Answers  


How to convert a string to long?

2 Answers  


Similarity and difference between static block and static method ?

0 Answers  


In a container there are 5 components. I want to display all the component names, how will you do that?

0 Answers  


What is void keyword?

0 Answers  


Categories