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

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 Pages:
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
ArrayList
Java Notes: ArrayList java.util.ArrayList allows for expandable arrays, and is the Collections replacement for the older Vector class. An ArrayList has the following advantages over an array: An ArrayList automatically expands
ArrayList
Java Notes: ArrayList java.util.ArrayList allows for expandable arrays, and is the Collections replacement for the older Vector class. An ArrayList has the following advantages over an array: An ArrayList automatically expands
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
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
arrayList
, ResultSet.TYPESCROLLINSENSITIVE,ResultSet.CONCUR_UPDATABLE); ps.setInt(1, st_code); rs = ps.executeQuery(); while (rs.next()) { dist_code= rs.getInt(1); dist_name=rs.getString(2
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 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
Sorting an ArrayList
Sorting an ArrayList  print("code sample");Hello All, I am working.... Here is my current code package gtt1_task2b; import java.util.Scanner; import... really new at Java...This is only the second program I am writing for school
Problem with arraylist
Problem with arraylist  I am currently working on a java project and there is an if loop within the for loop.... for(int i = 1;i < iterationsNo...()but it shows false  Please specify the full code. Check your if condition
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
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<E>
Java Notes: ArrayList<E> java.util.ArrayList<E> allows... class. An ArrayList has these characteristics: An ArrayList automatically expands as data is added. Access to any element of an ArrayList is O(1). Insertions
ArrayList problem - JSP-Servlet
ArrayList problem  Hi, How can I add elements of an ArrayList to HTML combobox or list in java? Hi, You can use the following code: Array List Example  Hi,You can use the following code:<!DOCTYPE HTML PUBLIC "
Java ArrayList
Java ArrayList   How to declare unique ArrayList
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
arraylist in java
arraylist in java  arraylist in java   Array List Example in java
arraylist problem - JSP-Servlet
arraylist problem  in my following code i have used a condition... the first row. i m new to java. so i have messed up the code. but please...(); ArrayList Code=new ArrayList(); ArrayList teamLeader
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 (non-generic)
Java Notes: ArrayList (non-generic) java.util.ArrayList allows.... An ArrayList has the following advantages over an array: An ArrayList automatically expands as data is added. Access to any element of an ArrayList is O(1
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
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
Eliminate Duplicates in Arraylist - Java Interview Questions
Eliminate Duplicates in Arraylist    Hi Friends, Can any one give sample code for removing duplicates in arraylist and hashmap. Thank u in advance.  Hi friend, Code to help in solving the problem
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
Convert List to ArrayList
to ArrayListCode Description: This program helps you in converting List to ArrayList.  Here we have taken a List of Colors or you can also take... Convert List to ArrayList      
Java arraylist, linkedlist
Java arraylist, linkedlist  What is the major difference between LinkedList and ArrayList
accessor arrayList
accessor arrayList  how to use an acccessor to return an arraylist... ArrayList(); //Add your item in the list return list; } You may wish to browse through some useful stuffs on Java at http://javaved.blogspot.com
Implementing ArrayList's functionalities into arrays - Java Beginners
Implementing ArrayList's functionalities into arrays  Hi guys, i'm... to organize data into arrays and MOST OF ALL how to do the same things that ArrayList allows with just a line of code, such as GET, ADD and REMOVE. Any ideas? Thanks
ArrayList programe
ArrayList programe  How to write a java program to accept an array list of Employee objects. search,delete and modify a particular Employee based on Id Number (like ID,Name&Address
Cannot assign an ArrayList to an empty ArrayList
Cannot assign an ArrayList to an empty ArrayList  I have a java file, in which a method returns an ArrayList. This ArrayList is supposed to contain... StudentsManager's methods statically. studByYear(year); returns an ArrayList of all
ArrayList example in JRuby
we have to include the ArrayList class as we import class file in simple java... ArrayList example in JRuby   ... and add elements in ArrayList using the JRuby. ArrayList is used to store
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
Java Code
Java Code  Write a java program, which creates multiple threads. Each thread performs add/delete/update operations on an ArrayList simultaneously
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
JSP Arraylist Index
Description: ArrayList is a class and a member of Java Collection Framework.... Code for JSP Arraylist index.jsp & postindex.jsp: index.jsp <%@page... and value to the postindex.jsp, which take all values and placed into the ArrayList
Convert ArrayList To Array
Convert ArrayList To Array       This is a simple program of java util.package. In this section, you will learn how to convert an Arraylist into an array.  Code Description
Java ArrayList, Java Array List examples
and it permits all the elements. The ArrayList also permits the null. Learn the ArrayList in Java with the example code. SampleInterfaceImp.java import...The Java ArrayList (java.util.ArrayList) is resizable implementation
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
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
problem in selecting second arraylist from mysql database
problem in selecting second arraylist from mysql database  Hi...everyone Below i have attached my code. This code is working.....but i want some modification in that code such that when i select 'vegetable' or 'fruits
How to update table column from the values of Arraylist in java
How to update table column from the values of Arraylist in java  Hii Sir, I have an arraylist containing these values [2, 1, 1, 1, 1, 1, 1... column of database table. plz give me the code of this problem.Thank you Sir
To Retrieve a Particular Object From an ArrayList
an ArrayList object (that contains multiple elements) using the get() method.... Create a class "Get" with an ArrayList .Populate it with the integer objects. Now retrieve an object( that is contained in the arraylist) using the get
arraylist with session - JSP-Servlet
arraylist with session  hi how can an arraylist stored in session.. and also how will it access?? pls give me the details with sample code..   Hi friend, Code to solve the problem : Thanks
Printing ArrayList - JSP-Servlet
Printing ArrayList   I have a code in servlet like this ArrayList total = new ArrayList (); session.setAttribute("efg",total...(request,response); to print the values in ArrayList total, I did this in my JSP
ArrayList - JSP-Interview Questions
ArrayList  i used arraylist in servlet as shown ArrayList total = new ArrayList (); ... total.add(k[i]); session.setAttribute("efg",total); when I code this like in my jsp <%ArrayList<Integer> data= new
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 - Java Beginners
in reverse order. (i don't know which programming is it, i think it is java

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.