Stream manner using a set of elements

com.itheima.demo03.Stream Package Penalty for ; 

Import java.util.ArrayList ;
Import java.util.stream.Stream ;

/ **
* @author newcityman
* @date 2019/8/4 - 20:30
* / *
* Exercise: collection processing element (Stream mode)
* there are two among a plurality of names of members of the set of storage ArrayList team required for the conventional cycle (or enhanced for loop) successively following several steps:
* 1. the first team long the name of a member of the three-word names; stored in a new collection.
* 2. The first team after the screening as long as the first 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. After the second team screened 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 Person objects by name; storage to a new collection.
* 7. print the entire team Person object information.
* /
Public class Demo02StreamTest {
public static voidmain (String [] args) {
// first team
the ArrayList <String> One = new new the ArrayList <> () ;
one.add ( "Dilly Reba") ;
one.add ( "Yuanqiao") ;
One. the Add ( "Su Xing") ;
one.add ( "Dan Potian") ;
one.add ( "Danzhong Yu") ;
one.add ( "I") ;
one.add ( "Zi") ;
one.add ( " Hong Qigong ") ;
// 1. the first team as long as the name for the three-word names of the members; storage to a new collection.
// 2. After the first screening of a team as long as the first three individuals; stored in a new collection.
. Stream <String> oneStream = one.stream () filter (name -> name.length () == . 3) .limit ( . 3) ;

The ArrayList <String> TWO = new new the ArrayList <> () ; two.add ( "Gülnezer Bextiyar") ; two.add ( "Zhang Wuji") ; two.add ( "Zhao Liying") ; two.add ( "Zhang San" ) ; two.add ( "Nicholas Zhao Si") ; two.add ( "Zhang day love") ; two.add ( "Zhang Ergou") ; // 3. the second team as long as the surname of the names of the members; stored a new collection. Do the first two personal // 4. The second team after the screening; storage to a new collection. Stream <String> twoStream = two.stream () filter (name -> name.startsWith (. "Zhang")) Skip (. 2) ; // 5. The two teams will be merged into a team; stored in a new collection in. // 6. Create Person objects by name; storage to a new collection. // 7. Print Person object information for the entire team. Stream.













concat(oneStream,twoStream).map(name->new Person(name)).forEach(p-> System.out.println(p));
}
}

Guess you like

Origin www.cnblogs.com/newcityboy/p/11300043.html