Title
now among a plurality of names of the members of a set of two storage ArrayList team required for a conventional loop (or enhanced for loop) successively following several steps:
1. The first team member's name as long as the name for the three-word; stored in a new collection.
2. After the first screening of a team long before the three individuals; stored in a new collection.
3. The second team member's name as long as Zhang's; storage to a new collection.
4. The second team after the screening of the first two do not personal; storage to a new collection.
5. The two teams as a combined team; stored in a new collection.
6. Create a Person object by name; storage to a new collection.
7. Print the entire team Person object information.
import java.util.*; import java.util.stream.Stream; public class SocketLearning { public static void main(String[] args) { // Method (); // a non-streaming mode stream stream (); } public static void Stream () // Stream stream treatment { // first team the ArrayList <String> One = new new the ArrayList <> (); one.add ( "Dilly Reba" ); one.add ( "Yuanqiao" ); one.add ( "Su Xing" ); one.add ( "Dan Potian" ); one.add ( "Shi Zhongyu" ); one.add ( "I" ); one.add ( "Zi" ); one.add ( "Hong Qigong" ); Stream<String> oneStream = one.stream().filter(name-> name.length()==3).limit(3); // second teams the ArrayList <String> TWO = new new the ArrayList <> (); two.add ( "Coulee Nazha" ); two.add ( "Zhang Wuji" ); two.add ( "Zhao Liying" ); two.add ( "Chi Master" ); two.add ( "Nicholas Zhao Si" ); two.add ( "Zhang day love" ); two.add ( "Zhang Ergou" ); Stream<String> twoStream = two.stream().filter(name-> name.startsWith("张")).skip(2); Stream.concat(oneStream, twoStream).map(name->new Person(name)).forEach(p-> System.out.println(p)); } public static void Method () // non-streaming mode stream, especially cumbersome { // first team the ArrayList <String> One = new new the ArrayList <> (); one.add ( "Dilly Reba" ); one.add ( "Yuanqiao" ); one.add ( "Su Xing" ); one.add ( "Dan Potian" ); one.add ( "Shi Zhongyu" ); one.add ( "I" ); one.add ( "Zi" ); one.add ( "Hong Qigong" ); ArrayList<String> one1 = new ArrayList<String>(); for(String name : one) { if(name.length()==3) { one1.add(name); } } ArrayList<String> one2 = new ArrayList<String>(); for(int i = 0; i < 3 ; i++) { one2.add(one1.get(i)); // i = 0,1,2; } // second teams the ArrayList <String> TWO = new new the ArrayList <> (); two.add ( "Coulee Nazha" ); two.add ( "Zhang Wuji" ); two.add ( "Zhao Liying" ); two.add ( "Chi Master" ); two.add ( "Nicholas Zhao Si" ); two.add ( "Zhang day love" ); two.add ( "Zhang Ergou" ); ArrayList<String> two1 = new ArrayList<String>(); for(String name : two) { if(name.startsWith("张")) { two1.add(name); } } ArrayList<String> two2 = new ArrayList<String>(); for(int i = 2; i < two1.size(); i++) { two2.add (two1.get (I)); // I do not contain 0,1 } ArrayList<String> all = new ArrayList<String>(); all.addAll(one2); all.addAll(two2); ArrayList<Person> list = new ArrayList<Person>(); for(String name : all) { list.add(new Person(name)); } for(Person person : list) { System.out.println(person); } } } class Person { private String name; Person(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String toString() { return "Person{"+"name="+name+"}"; } }