yandex
loader

please wait

  • Imran Malik Mar-15-2019 06:32:23 AM ( 2 months ago )

    In Java, How to remove null or 0 or not required values and return values with only required range.

    Example:
    [4,9,0,0]
    
    Result:
    [4,9]

    What I tried is:

    int someIndex = Arrays.asList(arr).indexOf(null);
    arr = Arrays.copyOfRange(arr,0,someIndex);

    Is there any java inbuilt functions available to trim array?

  • Jadav Payeng Mar-15-2019 06:33:47 AM ( 2 months ago )

    How about:

    Arrays.stream(arr).filter(v -> v != 0).toArray();

Please login

Similar Discussion

Recommended For You