I wrote the code to remove the duplicate id from Employee list and print unique one with all their details.
So here I am able to remove the duplicate and printing unique, but other employee details not printing
can you please help me on this issue to print the Employee Name, salary with their unique details?
Here is my snip of code
Employee POJO
package com.demo.streams;
public class Employee {
Integer empId;
String name;
Double salary;
public Employee(Integer empId, String name, Double salary) {
this.empId = empId;
this.name = name;
this.salary = salary;
}
public Integer getEmpId() {
return empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPhone() {
return salary;
}
public void setCity(Long phone) {
this.salary = salary;
}
@Override
public String toString() {
return "Name :" + name + " Phone :" + salary + " Emp Id :" + empId;
}
}
My Main Class
public class RemoveDuplicateId {
public static void main(String[] args) {
List<Employee> listObj = Arrays.asList(new Employee(5, "Raju", 8967452, "Infosys"),
new Employee(6, "Shayam", 78564589, "Tcs Ltd"), new Employee(3, "Mantu", 677890, "Wipro"),
new Employee(5, "Shayam", 878965, "Tech-Mahindra"), new Employee(8, "Guudu", 987653, "Cisco"));
List<Integer> id = listObj.stream().map(e -> e.geteId()).distinct().collect(Collectors.toList());
for (Integer sorted : id) {
System.out.println(sorted);
}
}
}
out put
5
6
3
8
So here I am able to remove the duplicate and printing unique, but other employee details not printing
can you please help me on this issue to print the Employee Name, salary with their unique details?
Here is my snip of code
Employee POJO
package com.demo.streams;
public class Employee {
Integer empId;
String name;
Double salary;
public Employee(Integer empId, String name, Double salary) {
this.empId = empId;
this.name = name;
this.salary = salary;
}
public Integer getEmpId() {
return empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Double getPhone() {
return salary;
}
public void setCity(Long phone) {
this.salary = salary;
}
@Override
public String toString() {
return "Name :" + name + " Phone :" + salary + " Emp Id :" + empId;
}
}
My Main Class
public class RemoveDuplicateId {
public static void main(String[] args) {
List<Employee> listObj = Arrays.asList(new Employee(5, "Raju", 8967452, "Infosys"),
new Employee(6, "Shayam", 78564589, "Tcs Ltd"), new Employee(3, "Mantu", 677890, "Wipro"),
new Employee(5, "Shayam", 878965, "Tech-Mahindra"), new Employee(8, "Guudu", 987653, "Cisco"));
List<Integer> id = listObj.stream().map(e -> e.geteId()).distinct().collect(Collectors.toList());
for (Integer sorted : id) {
System.out.println(sorted);
}
}
}
out put
5
6
3
8
Abhishek Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.