Converting ArrayList to Array in java

前端 未结 10 1860
野的像风
野的像风 2020-12-04 18:44

I have an ArrayList with values like \"abcd#xyz\" and \"mnop#qrs\". I want to convert it into an Array and then split it with # as delimiter and have abcd,mnop in an array a

10条回答
  •  不知归路
    2020-12-04 19:37

    This can be done using stream:

    List stringList = Arrays.asList("abc#bcd", "mno#pqr");
        List objects = stringList.stream()
                                           .map(s -> s.split("#"))
                                           .collect(Collectors.toList());
    

    The return value would be arrays of split string. This avoids converting the arraylist to an array and performing the operation.

提交回复
热议问题