2016-11-22 39 views

回答

1

的Java 8

你可以得到的String []流以這樣的方式

List<String> array = Arrays.asList("A","B","C","D"); 
    String[] st ={""}; 
    Stream<String[]> stream = array.stream().map(x -> (st[0]+=x).split("\\B")); 
    //print it 
    stream.forEach(s -> System.out.println(Arrays.toString(s))); 

RX JAVA(擴大JohnWowUs的答案)

List<String> array = Arrays.asList("A","B","C","D"); 
Func2<String,String,String> function = new Func2<String,String,String>(){ 
    @Override 
    public String call(String paramT1, String paramT2) { 
     return paramT1 + paramT2; 
    } 
}; 
Observable<String> scan = Observable.from(array).scan(function); 
scan.forEach(x-> System.out.println(x));