Convert an array to list with specific range in Java 8

  • A+
Category:Languages

I want to convert one string array to list with specific range. In my case I always want from index 1 to last index. I don't need the index 0 value included in the list. Is there any direct method that I can use to filter and convert to the list as I need ?

public class test1 {      public static void main(String[] args) {         String[] optArr = {"start", "map1", "map2", "map3"};         List<String> list = Arrays.stream(optArr).collect(Collectors.toList());         System.out.println(list);     } } 

 


You can use Stream.skip():

List<String> list = Arrays.stream(optArr).skip(1).collect(Collectors.toList()); 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: