java - Add index number to each element in collection using FluentIterables in Guava -


i have list of string elements transform using fluentiterables.transform. sake of example let's is:

list<string> l = arrays.aslist("a", "b", "c"); 

now add index number each element result be:

"0a", "1b", "2c" 

is there way acomplish in nice way using guava?

you can stateless transformation function if start indices instead of list elements. here's example java 8 streams:

list<string> list = arrays.aslist("a", "b", "c"); intstream.range(0, list.size())     .maptoobj(i -> + list.get(i))     .foreachordered(system.out::println); //or .collect(collectors.tolist()), ... 

you can same fluentiterable suitable index generator, such contiguousset.create(range.closedopen(0, list.size()), discretedomain.integers()).


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -