Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

Array list java program

Ads

 
 

Share on Google+Share on Google+

venkatesh
Array list java program
2 Answer(s)      7 years ago
Posted in : Java Interview Questions
Ads
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

Ads









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
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 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
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
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
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
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 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 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
array list
array list  How to get repeate occurence values from database table in java by using arraylist
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
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...[]=new int[10]; System.out.println("Array of Random Numbers
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
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
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 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
array list example
array list example  Array list example   Hello Friend, Please visit the following links: Array List Example1 Array List Example2 Thanks
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
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
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
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
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
Convert Array to List
Convert Array to List       In this section, you will learn to convert an Array to List.  Code Description: This program helps you in converting an Array to List. Here we
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
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