0

How to enter data in instance variables of object in arraylist from user on runtime in java?

Here is the code ArrayList<Employee> list = new ArrayList<Employee>(); Employee emp1 = new Employee("Saad", 1); Employee emp2 = new Employee("Arsh", 2); list.add(emp1); list.add(emp2); for (Employee employee : list) { System.out.println(employee.toString());

8th Feb 2019, 2:35 PM
S.K
9 Answers
+ 3
S.K i didn't get your question. Can you describe more please?
8th Feb 2019, 2:43 PM
Seniru
Seniru - avatar
+ 3
Sample input and output pls
8th Feb 2019, 2:50 PM
Seniru
Seniru - avatar
+ 2
S.K I will. But I need to know what kind of input you are going to take and the relevant output for it
8th Feb 2019, 2:53 PM
Seniru
Seniru - avatar
+ 1
I need object array. Data should be entered through scanner from user. It should work exactly the same, but need to take data from user through scanner. Can you help please ? Seniru Pasan [OFFLINE 👎]
8th Feb 2019, 2:45 PM
S.K
+ 1
Code it please. I am struggling with it.
8th Feb 2019, 2:51 PM
S.K
+ 1
Hope this helps: https://code.sololearn.com/cSbSjTPNB9N1/?ref=app Maybe a Hashmap could be also interesting for you: https://www.sololearn.com/learn/Java/2181/?ref=app to implement a scanner: Scanner input = new Scanner (System.in); String name = input.nextLine (); int id = input.nextInt (); Employee emp = new Employee (name, id);
9th Feb 2019, 8:38 AM
Denise Roßberg
Denise Roßberg - avatar
9th Feb 2019, 12:47 PM
S.K
0
I am writing a statement.
8th Feb 2019, 2:54 PM
S.K
0
1. I need a class Employee 2. Employee should have name and id. 3. Array should be dynamic, means users should enter how many employee data he needs to enter. 4. Then enter the values through scanner i.e name and id. 5. Print it.
8th Feb 2019, 2:57 PM
S.K