//---- You can use this example to understand how to set and get data in java --- //
package aman.sort;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Run {
/**
* @param args
*/
public static void main(String[] args) {
List dataBean = new ArrayList();
try {
String ch;
do{
DataBean bean = new DataBean();
ch="";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the User :");
String name = br.readLine();
bean.setName(name);
System.out.println("Enter the Id :");
int id = (Integer.parseInt(br.readLine()));
bean.setId(id);
dataBean.add(bean);
System.out.println("Press 'y' for input again data... ");
ch = br.readLine();
}while((ch.equals("y"))||ch.equals("Y"));
}
catch(Exception e) {
System.out.println("Error occured due to input invalid data..."+e);
}
for(Object obj: dataBean) {
DataBean getbean = (DataBean)obj;
System.out.println("name is :"+getbean.getName()+"Id is:"+getbean.getId());
}
}
}
//=================================================
No comments:
Post a Comment