Java - get element position in array

后端 未结 4 1880
谎友^
谎友^ 2021-01-03 20:47

I\'m familiar with the ways I can get an element position in array, especially the ones showed here: Element position in array

But my problem is I can\'t figure out

4条回答
  •  粉色の甜心
    2021-01-03 21:25

    just use the call listPackages.indexOf(current_package);

    ArrayList.contains(Object o) calls indexOf(Object o) internally in ArrayList:

    /**
     * Returns true if this list contains the specified element.
     * More formally, returns true if and only if this list contains
     * at least one element e such that
     * (o==null ? e==null : o.equals(e)).
     *
     * @param o element whose presence in this list is to be tested
     * @return true if this list contains the specified element
     */
    public boolean contains(Object o) {
    return indexOf(o) >= 0;
    }
    

提交回复
热议问题