Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class HelloWorld{
public static class Person {
public String name;
public String address;
public Integer age;
public Person(String name, String address, Integer age) {
this.name = name;
this.address = address;
this.age = age;
}
@Override
public String toString() {
return name + " " + address + " " + age;
}
}
public static class Result {
public String name;
public String address;
public Result(String name, String address) {
this.name = name;
this.address = address;
}
@Override
public String toString() {
return name + " " + address;
}
}
public static void main(String []args){
List<Person> people = Arrays.asList(new Person("Hoang", "1", 19), new Person("Hoa", "2", 20));
List<Result> result = people.stream().map(p -> new Result(p.name, p.address)).collect(Collectors.toList());
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.