Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


venkatesh
Arraylist java code
2 Answer(s)      5 years and 2 months ago
Posted in : Java Interview Questions



Advertisement
View Answers

August 24, 2009 at 4:45 PM


Hi Friend,

Try the following code:

import java.util.*;
import java.io.*;
public class DisplayArrayListData {
int id;
String name;
String address;
static ArrayList employeeList = new ArrayList();
static int count = 0;
DisplayArrayListData(){}

DisplayArrayListData(int id, String name, String address){
this.id = id;
this.name = name;
this.address = address;
count++;
}
public void setDetails(DisplayArrayListData data){
employeeList.add(data);
}
public DisplayArrayListData getDetails(int id){
DisplayArrayListData data = (DisplayArrayListData)employeeList.get(id);
return data;
}
public static void main(String[] args) throws Exception{

DisplayArrayListData displaydata = new DisplayArrayListData();
DisplayArrayListData data1 = new DisplayArrayListData(1, "A", "Delhi");
DisplayArrayListData data2 = new DisplayArrayListData(2, "B", "Mumbai");
DisplayArrayListData data3 = new DisplayArrayListData(3, "C", "Chennai");
DisplayArrayListData data4 = new DisplayArrayListData(4, "D", "Kolkata");
DisplayArrayListData data5 = new DisplayArrayListData(5, "E", "Hyderabad");
DisplayArrayListData data6 = new DisplayArrayListData(6, "F", "Delhi");

displaydata.setDetails(data1);
displaydata.setDetails(data2);
displaydata.setDetails(data3);
displaydata.setDetails(data4);
displaydata.setDetails(data5);
displaydata.setDetails(data6);

System.out.println(" ");
System.out.print("Enter Employee Id: ");
Scanner input=new Scanner(System.in);
int id = input.nextInt();
boolean flag = false;

for(int i=0; i<count;i++)
{
DisplayArrayListData data = data1.getDetails(i);
if(id == data.id)
{
System.out.println("Name and Address of employee is: ");
System.out.print(data.name+" " +data.address);
flag = true;
break;
}
}
}
}

Thanks


August 26, 2009 at 8:30 PM


THANKS ALOT. The java code for this query which u developed is very understandable and easy..Once again,thanks alot.


Related Tutorials/Questions & Answers:
ARRAYLIST CODE - Java Beginners
ARRAYLIST CODE  HELLO SIR,I AM VERY NEW TO JAVA FIELD,HOW TO READ ELEMENTS FROM TWO ARRAYLIST AND PRINT THE ELEMENTS WHICH ARE COMMON TO TWO ARRAYLIST IN ONE LINE AND OTHER IN NEXT LINE,PLZ HELP ME.IN ADVANCE THANK U VERY
java code for conversion of arraylist to string - Development process
java code for conversion of arraylist to string  Hi, i have an arraylist contains [a,b,value,c,d,value]when ever value comes it will split... by "value" as a delimiter  Hi friend, Code to solve the problem
Advertisements
Arraylist java code - Java Interview Questions
Arraylist java code  Create an employee class with an employee id's... an employee id is given, display his name & address? Please provide the java code Detaily...; i  THANKS ALOT. The java code for this query which u developed is very
Java ArrayList
Java ArrayList   How to declare unique ArrayList
arraylist in java
arraylist in java  arraylist in java   Array List Example in java
Java arraylist of arraylist
Java arrayList can make the use of other arrayList.  In one arrayList other arrayList can be added as the object  It works as two dimension array. Example of Java Arraylist of Arraylist import
java arraylist
help how to handle this through java arraylist. xml : <?xml version='1.0...java arraylist  Hi, Thanks in advance.. From the xml given below i need to create arraylist whose name is same as type value(e.g : list1,list2
ArrayList in java
ArrayList in java  sir i have a class Student.it contains id,name,marks of students and a parameteraised constructor.now i created an arraylist... to access marks from arraylist
Java arraylist, linkedlist
Java arraylist, linkedlist  What is the major difference between LinkedList and ArrayList
Java ArrayList Example
Java ArrayList Example  How can we use array list in java program..."); array.add("Arun"); System.out.println("ArrayList Size...++){ System.out.println("ArrayList Element"+i+" :"+array.get(i
Core Java-ArrayList
Core Java-ArrayList  How do i find duplicates in ArrayList. First i add some elements to ArrayList, then how do i find the duplicates and show the duplicate elements. Give an example
arraylist problem - Java Beginners
arraylist problem  Hello.... I wrote the following code for adding a string array into an array list along with other strings... and to display...{ ArrayList al = new ArrayList(); for(int i=0;i<10;i++){ String event
arrayList - Java Beginners
must check through the desktop arraylist and notebook arraylist. How can I combine this two arraylist checking for throw out the msg of "Computer list is empty!" Currently I only can check for desktop arraylist empty if no desktop is added
maximum size of arraylist - java
maximum size of arraylist - java  1.what is the maximum size of arraylist? 2.what is the drawback of arralist? 2.what is the drawback of JDBC? 4.how many access specifier and how many access modifier in java? 5.what
arraylist
arraylist   Using arraylist class , what type of exception are throws, how can write a java programe   An ArrayList can throw... ArraylistException { void buildAlphabet() { ArrayList list = new ArrayList
ArrayList - Java Beginners
"); //Vector vector=new Vector(); ArrayList arfray=new ArrayList... occurs, otherwise your code works fine. import javax.swing.*; import...("Show All"); Vector vector=new Vector(); ArrayList arfray=new ArrayList
arraylist - Java Beginners
arraylist  Hi.. I've an arraylist where i need to add a string array along with other string values. My string array is array[] and arraylist is al i added other string values name,time,date as al.add(name); al.add(time
Java arraylist duplicate elements search
Java arraylist duplicate elements search  hi, please help me finding the no of duplicates elements in an arraylist example an arraylist contains elements like: mac raj mohan frank mac tom raj mohan frank result: mac 2 raj
Java arraylist index() Function
Java arrayList has index for each added element. This index starts from 0. arrayList values can be retrieved by the get(index) method. Example of Java Arraylist Index() Function import
Java arraylist iterator
ArrayList has iterator() method.Using iterator() method  elements of the arraylist easily gets retrieved. iterator() can be used in the for loop. It is clear by the given example. Example of Java Arraylist
Arraylist in java
ArrayList is a class that extends AbstractList and implements List Interface. Standard java array are of fixed length, that mean we should know the size.... but for indefinite number of elements Arraylist is used as it creates dynamic Array
ArrayList - Java Beginners
in reverse order. (i don't know which programming is it, i think it is java
How to sort ArrayList in java
which sort the Arraylist. Now here is the code to sort the ArrayList in java...How to sort ArrayList in java In this section you will learn how to sort ArrayList in java. ArrayList support dynamic array that can grow as needed. Array
Java ArrayList sublist
It returns the part of the ArrayList as List reference. part is the given range between two indexes. Java Arraylist Sublist Example import...) { String  ar[]={"india","pakistan","United Kingdom","Japan","Korea"}; ArrayList
Java ArrayList removeall
the elements from list1 which is present in the list2 Java Arraylist Removeall...","Korea"}; ArrayList list=new ArrayList(); ArrayList list1=new ArrayList
Java new arraylist
Java ArrayList object is created with the reference of List interface Object is also created directly by the ArrayList class Java New Arraylist..."}; //ArrayList list=new ArrayList(); List list=new ArrayList(); list.add(ar[0
Java arraylist for loop
Elements of the ArrayList can be easily added and retrieved by the for loop. Example FOR Java arraylist for loop import java.util.ArrayList...(String[] args) {         List list=new ArrayList();         String names
arraylist
arraylist  Hi how can we eliminet duplicate element from arraylist in java? how can we achieve data abstrcation and encapulation in java? how many type of modifier are there in java? Thanks kalins anik   Remove
Collections arraylist - Java Interview Questions
....and what will be the code for that?  Hi Friend, Try the following code: import java.util.*; class SynchronizedArrayList{ public static void main(String[] args) { ArrayList al=new ArrayList(); al.add("1"); al.add("2
Java ArrayList clone
It returns the copy of the given ArrayList object as the Object class. So it must be casted to the ArrayList for further use. Java Arraylist...","Japan"}; ArrayList list=new ArrayList(); list.add(ar[0]); list.add(ar[1
Java arraylist merge
is joined in to the list1. Example Java Arraylist Merge import... In Java Two arrays can be joined by using the Collection list...};         List list1=new ArrayList();         List list2=new ArrayList
Advertisements
 

 

 

DMCA.com