This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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