ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
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?
 Question Submitted By :: Seenu
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
for(int i=0;i<arr.size();i++){
			if(arr.get(i) instanceof Integer)
				arr.remove(i);
		}
 
Is This Answer Correct ?    3 Yes 1 No
Murli
 
  Re: 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
# 2
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 ?    1 Yes 0 No
Srivatsava
 
 
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Difference between overloading and overridding?  4
C and C++ has constructors and distructors, why does Java does not have distructors? T3-Softwares1
What is the middleware?  2
I have an HashMap object, which has with key and value pair. It has 10 keys and values in that object. Now the question is I want insert new key and value in middle or any where in that list but not at the end or at the top. Is it possible or not. If yes how can we achieve this one? Huawei1
What is the exact difference in between Unicast and Multicast object ? Accenture1
explain about jre and jvm  2
why abstract class will have a constructor?  3
What restrictions are placed on method overloading and method overriding?  3
How to transfer data from an Applet to Servlet ?  1
Name the types of 'priority'?  2
What is meant by controls and types?  1
Name the types of mouse event listeners ?  2
Different types of modifiers? RoboCom3
What is hypertext?  1
what is stringtolennizer with example? Symphony1
what is business delegate? TCS2
How to add panel to a Frame?  2
Why Java is not purely object oriented? Persistent21
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? Aricent2
What are hot spots in Java programming?  1
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com