Array list java program

Array list java program

View Answers

August 26, 2009 at 5:47 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.util.*;

class Employee{
public int id;
public String name;
public String address;
public static int count = 0;
public Employee(){}
public Employee(int id, String name,String address) {
super();
this.id = id;
this.name = name;
this.address=address;
count++;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
}
public class DisplayArrayList {

public static void main(String[] args) throws Exception {
List<Employee> list = new ArrayList<Employee>();
list.add(new Employee(1, "A","Delhi"));
list.add(new Employee(2, "B","Mumbai"));
list.add(new Employee(3, "C","Chennai"));
list.add(new Employee(4, "D","Kolkata"));
System.out.println(" ");
System.out.print("Enter Employee Id: ");
Scanner input=new Scanner(System.in);
int id = input.nextInt();
for (Employee s : list){
if(id == s.getId())
{
System.out.println("Name and Address of employee is: ");
System.out.print(s.getName()+" " +s.getAddress());

}
}
}
}

Thanks

August 26, 2009 at 8:47 PM

Thanks alot..the java code which you provide for my query is very clear..thanks alot again









Related Tutorials/Questions & Answers:
Array list java program - Java Interview Questions
Array list java program  Create an employee class with an employee... an employee id is given, display his name & address? Please provide the DETAIL java... we can display his name and address when an employee id is given? i need java
array variable in a java program
array variable in a java program  How do i write a program that will prompt the user for a list of 5 prices, that cosist of the sum of all the prices, the average of the prices, and all prices that are higher than the calculated
Advertisements
java program based on array
java program based on array  write a program to create an array of 10 integers in main.accept values from the user in that array .now again ask the use another nomber and pass the array and the no. entered to function called
java program based on array
java program based on array  Create Student class with attributes... StudentDemo which will have main method. Declare array of Student object with size 10. Initialize all 10 elements of this array with new objects. Write logic which
array program
array program  write a java program which will take 10 elements as command line arguments and count how many times 3 occurs in array
Create list from array in Java
Create list from array in Java  Hi, I have an array with some data. How to Create list from array in Java? Thanks   Hi, Here is example of creating of creating an array: String[] names = new String[]{"Java", "JSP
java 2 d array program
java 2 d array program  write a program 2-d matrix addition through user's input?  Hi Friend, Try the following code: import java.util.*; class MatrixAddition{ public static void main(String[] args
How to Serialize and Deserialize Array List in Java?
); Here is Java program code to save Array List object to a file: package...Java Serialization: How to Serialize and Deserialize Array List in Java... the values stored in the list. This way you can use the serialization of Java
How to Serialize and Deserialize Array List in Java?
Java Serialization: How to Serialize and Deserialize Array List in Java... the values stored in the list. This way you can use the serialization of Java... Java program that will serialize the object of ArrayList into a file. Here we
How to Convert array to list in Java
How to Convert array to list in Java  Hi, I have object of array in Java and I want to convert it to list. How to Convert array to list in Java... ArrayList to list in Java. (adsbygoogle = window.adsbygoogle || []).push
program of array
program of array  write a program that initializes an array with ten random integers and then prints four lines of output,containing:every element at an even index,every even element,all elements in reverse order,and only
java list program for common elements
java list program for common elements  hi I want program using java collections list which takes two array list elements and display common elements in both the list as an output   Please visit the following link
create and use an array variable in a java program
create and use an array variable in a java program  how do i write a program that will prompt the user for a list of 5 prices, once the user has entered all values , your program should compute and display the following: The sum
program in array
program in array  print("code sample");write a program that initializes an array with ten random integers and then prints four lines of output...(); int arr[]=new int[10]; System.out.println("Array of Random
Array list in Java - arraylist type error
Array list in Java - arraylist type error  I am using Array list in Java but when i compile i get array list type error. Can anyone please explain what is array list type error and why it occurs
array list
array list  How to get repeate occurence values from database table in java by using arraylist
Array List
Array List   Complete the class House and HouseApp below to display class House{ int lotNo; String type; //Bungalow, SemiDetached double price... below as the program input: HOUSES IN TAMAN ILMU LotNo Type Price 10021
Array List
Array List  Could somebody help me to solve this question. I am glad to hear ideas or answers from everyone. The situation: Complete the class House...?¦. â?¦â?¦â?¦. Use the information below as the program input
Array list java code - Java Beginners
Array list java code  Create an employee class with an employee id's,name & address. Store some objects of this class in an arraylist. When an employee id is given, display his name & address? Please provide the DETAIL java code
Array list java code - Java Interview Questions
Array list java code  Create an employee class with an employee id's... an employee id is given, display his name & address? Please provide the DETAIL java code... in your code?Please clarify it. Thanks  i need the java code
Program to implement array of Objects.
Program to implement array of Objects.  Create a class it has.... Initialize an array of objects. Pass a name from the command line & search for the name in the array of objects , if it is existing print the information
Java ArrayList, Java Array List examples
The Java ArrayList (java.util.ArrayList) is resizable implementation of the List interface. It has support for all the functions present in the List interface... the ArrayList in Java with the example code. SampleInterfaceImp.java import
how to make a program on array
how to make a program on array  When you make a program on array that the element will move downward and upward and when you input twice 0 then thats the time that it will not move. pls. give me a formula...tnx
array list example
array list example  Array list example   Hello Friend, Please visit the following links:ADS_TO_REPLACE_1 Array List Example1 Array List Example2 ThanksADS_TO_REPLACE_2
one dimensional array program
one dimensional array program  Design and implement a java program that will read a file containing numbers and compute the following statistics: the rannge( low, high), the average and the median(middle number). Notes
Two Dimensional array program
to elements of the array such that the last element become the first one and the first become the last.let the program output elements of the first array...Two Dimensional array program  consider a two dimensional array
array of students with marks list
and therefore no score available. Write a java program that will return the highest...array of students with marks list  There are 4 array of numbers or scores as below. They are called marks list and represent the scores individual
Three Dimensional Array program
Three Dimensional Array program       This is a very simple Java program. In this program we... the multidimensional array we are going to make a matrix. Now in this program use
Sorting Array List in Java
Sorting Array List in Java In this example you will learn about sorting array list in java using an example. By default array list are sorted as the element are inserted into the list. In Java ArrayList extends AbstractList implements
Reverse integer array program
Reverse integer array program  Been tasked with the following question: Write a method that accepts an integer array and returns a new array with all the elements in reverse order. For example, if the input array is [2, 4, 6, 8
Two Dimensional Array Program
;    This is very simple program of Java. In this lesson we will learn how to display arrange form of two dimensional array program... a integer for array declaration Two dimensional array program. We are going
getting html list in a array
getting html list in a array  hi i want to get html unordered list in a array using jsp
getting html list in a array
getting html list in a array  hi i want to get html unordered list in a array using jsp
program to implement array of objects
program to implement array of objects  import java.io.*; import java.util.*; public class dataa { DataInputStream in=new DataInputStream(System.in); int i; int a[i]=int acid[5]; String name1[i]=new String[5
Array List and string operation
Array List and string operation  hi, I want to search an arraylist element in a a given file. example I have a name called "mac" in my arraylist and I have a txt file which contains mac, how many times "mac" appears in the txt
Convert Array to List
Convert Array to List       In this section, you will learn to convert an Array to List.  Code Description:ADS_TO_REPLACE_1 This program helps you in converting an Array
Convert List to Array
Convert List to Array       Lets see how to convert List to Array.  Code Description: In this program we have taken a List of type String as shown below. For this we have used
Two Dimensional Array Program
Two Dimensional Array Program Using Nested for loop       This is a simple Java array  program . In this session we will teach how to use of a two dimensional array
java program
java program  write a java program to display array list and calculate the average of given array
java program
java program  write a java program to display array list and calculate the average of given array
Java array
Java array  Java program to find first two maximum numbers in an array,using single loop without sorting array
Two Dimensional Array Program Using Nested For Loop
Two Dimensional Array Program Using Nested For Loop        This is very simple program... dimensional array program. Firstly, we have to define class "TwoDimensional "
PHP list array keys
array_keys() function returns the keys of the the given array. It returns the keys in the form of array. Example of PHP list Array Keys <?php     $ar1=array("x"=>"x-mas","y"=>"yak","zebra");  
java array
java array  q4.array Write a program that accepts two arrays, an array of fruit names and an array of price of fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the second array corresponds
Changing the value of Array in Java
array program is provided Java application program about the explanation... Changing the Value of Array in Java       This is very simple of one dimensional array program
Shuffling the Element of a List or Array
Shuffling the Element of a List or Array   ... the list or array to prepare each and every element for the operation. In this section, you will learn about shuffling the element of a list or array. Shuffling
Java Array
Java Array   a) Write an array program that perform the following: i) Declares a String array initialized with the following strings: ââ?¬Å...?¬Â?. ii) Write a loop that displays the contents of each element in the array
Java array
Java array   How can one prove that the array is not null but empty
java array
java array  write a java method that takes an array of float values...)){ System.out.println("There are duplicate elements."); Float array...++){ array[i]=new Float(arr[i]); } Set<Float>
java program
java program  write a java program to create an array of size 10 by taking input from bufferreader and find out the average of array elements from that array

Ads