How do I convert a List in Java 8? -


In Java 8, I can write

  list & lt; String & gt; StrList = Arrays.asList ("1", "2", "3"); & Lt; Integer & gt; IntList = strList.stream (). Map (S -> integer.value (s)). Collections (collectors list);  

And it is very less than before, but I have these conversions and I wonder why the following is not possible, that is why the conversion / conversion method is not there?

  // will not work because there is no conversion in the list () or conversion () method: list & lt; Integer & gt; IntList = strList.convert (s -> integer.whouf (s));  

If the implementation of convert will be clever, it may also be lazy, so that the conversion is done only when the elements are actually requested. Will go / P>

Alternatively, I can definitely write it myself, but does anyone know of a library that provides a method?

  // Any ideas that this experiment provides? & Lt; Integer & gt; IntList = SomeLibraryUtil.convert (strList, s -> integer.valouf (s));  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -