java howto ArrayList push, pop, shift, and unshift

前端 未结 5 477
我在风中等你
我在风中等你 2020-12-12 17:19

I\'ve determined that a Java ArrayList.add is similar to a JavaScript Array.push

I\'m stuck on finding ArrayList functions sim

5条回答
  •  半阙折子戏
    2020-12-12 17:34

    Underscore-java library contains methods push(values), pop(), shift() and unshift(values).

    Code example:

    import com.github.underscore.U:
    
    List strings = Arrays.asList("one", "two", " three");
    List newStrings = U.push(strings, "four", "five");
    // ["one", " two", "three", " four", "five"]
    String newPopString = U.pop(strings).fst();
    // " three"
    String newShiftString = U.shift(strings).fst();
    // "one"
    List newUnshiftStrings = U.unshift(strings, "four", "five");
    // ["four", " five", "one", " two", "three"]
    

提交回复
热议问题