Retrieving an element from array list in Android?

后端 未结 6 2034
醉话见心
醉话见心 2021-02-01 07:16

I am trying to implement voice recognition code in Android. How do I get an element at a particular position from array list in Android? I tried converting arraylist

6条回答
  •  隐瞒了意图╮
    2021-02-01 07:42

    What I understand your question is that you want to fetch an element in an ArrayList at a specific location.

    Suppose your list contains Integers 1,2,3,4,5 and you want to fetch the value 3. Then the following lines of code will work.

    ArrayList list = new ArrayList();
            if(list.contains(3)){//check if the list contains the element
                list.get(list.indexOf(3));//get the element by passing the index of the element
            }
    

    Either ways you could use list.get(list.lastIndexOf(3))

提交回复
热议问题