i need to find a integer data in arraylist?

后端 未结 4 769
抹茶落季
抹茶落季 2020-12-16 14:26

I have an Arraylist. If user enter the same number secondly I want to show to user. For this I need to find Arraylist have it or not.

I hop

4条回答
  •  鱼传尺愫
    2020-12-16 14:40

    If you are checking to see if some value is stored in an ArrayList you can use the contains() method, this will return true if the object is in the list, false otherwise.

    ArrayList intList = new ArrayList<>();
    
    intList.add(5);
    intList.add(7);
    intList.add(3);
    intList.add(-2);
    
    intList.contains(-1); //returns false
    intList.contains(3); //returns true
    

提交回复
热议问题