Splitting a space separated list

前端 未结 8 1127
暖寄归人
暖寄归人 2021-01-04 09:01

This is a common task I\'m facing: splitting a space separated list into a head element and an array containing the tail elements. For example, given this

8条回答
  •  独厮守ぢ
    2021-01-04 09:25

    For certain values of elegant:

    String input = "The quick brown fox";
    String[] elements = input.split(" ");
    String first = elements[0];
    String[] trailing = Arrays.copyOfRange(elements,1,elements.length);
    

    I can't think of a way to do it with less code...

提交回复
热议问题