package com.java2novice.collections;
import java.util.Collections;
import java.util.List;
public class MyObjectNCopies {
public static void main(String a[]){
String temp = "JAVA2NOVICE";
List<String> tempCopies = Collections.nCopies(5, temp);
System.out.println(tempCopies);
Empy emp = new Empy(10, "Raghu", 25000);
List<Empy> empCopies = Collections.nCopies(5, emp);
for(Empy e:empCopies){
System.out.println(e);
}
}
}
class Empy{
private int id;
private String name;
private Integer salary;
public Empy(int id, String name, Integer sal){
this.id = id;
this.name = name;
this.salary = sal;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getSalary() {
return salary;
}
public void setSalary(Integer salary) {
this.salary = salary;
}
public String toString(){
return id+" "+name+" "+salary;
}
}
|