RxJava: How to convert List of objects to List of another objects

后端 未结 9 475
悲哀的现实
悲哀的现实 2021-01-31 07:30

I have the List of SourceObjects and I need to convert it to the List of ResultObjects.

I can fetch one object to another using method of ResultObject:

c         


        
9条回答
  •  不思量自难忘°
    2021-01-31 07:43

    Don't break the chain, just like this.

    Observable.from(Arrays.asList(new String[] {"1", "2", "3", }))
    .map(s -> Integer.valueOf(s))
    .reduce(new ArrayList, (list, s) -> {
        list.add(s);
        return list;
    })
    .subscribe(i -> {
        // Do some thing with 'i', it's a list of Integer.
    });
    

提交回复
热议问题