package StreamStudy.Exa03;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class StreamChange {
public static void main(String[] args) {
String content="hello world, wo cao ni ma ma ni wo";
String[] contents=content.split("\\PL+");
Stream<String> words= Stream.of(contents);
Stream<String> changeWords=words.map(String::toUpperCase);
List<String> result=changeWords.collect(Collectors.toList());
System.out.println(result);
List<String> result2=Stream.of(contents).map(s->s.substring(0,1)).collect(Collectors.toList());
System.out.println(result2);
Stream<Stream<String>> result3=Stream.of(contents).map(w->letters(w));
List<String> restr=new ArrayList<>();
for(Stream<String> stream:result3.collect(Collectors.toList())){
restr.addAll(stream.collect(Collectors.toList()));
}
System.out.println(restr);
List<String> restrs=Stream.of(contents).flatMap(w->letters(w)).collect(Collectors.toList());
System.out.println(restrs);
Stream<Double> randoms=Stream.generate(Math::random).limit(10);
List<Double> randomList=randoms.collect(Collectors.toList());
System.out.println(randomList);
List<Double> skipList=Stream.generate(Math::random).limit(10).skip(5).collect(Collectors.toList());
System.out.println(skipList);
List<Double> concatList=Stream.concat(Stream.generate(Math::random).limit(5),Stream.generate(Math::random).limit(5)).collect(Collectors.toList());
System.out.println(concatList);
List<String> distinctList=Stream.of(contents).distinct().collect(Collectors.toList());
System.out.println(distinctList);
List<String> sortedList=Stream.of(contents).sorted().collect(Collectors.toList());
System.out.println(sortedList);
List<String> sortedList2=Stream.of(contents).sorted(Comparator.comparing(String::length)).collect(Collectors.toList());
System.out.println(sortedList2);
List<String> sortedList3=Stream.of(contents).sorted(Comparator.comparing(String::length).reversed()).collect(Collectors.toList());
System.out.println(sortedList3);
List<String> peekList=Stream.of(contents).peek(e-> System.out.println("元素"+e)).limit(5).collect(Collectors.toList());
System.out.println(peekList);
}
public static Stream<String> letters(String s){
List<String> result=new ArrayList<>();
for(int i=0;i<s.length();i++){
result.add(s.substring(i,i+1));
}
return result.stream();
}
}
