Arrays can only be compared with Arrays.equals().

You probably want an ArrayList of ArrayLists.

ArrayList<ArrayList<Integer>> j = new ArrayList<ArrayList<Integer>>();
ArrayList<Integer> w = new ArrayList<Integer>();
w.add(1); w.add(2);
j.add(w);
ArrayList<Integer> t = new ArrayList<Integer>();
t.add(1); t.add(2);
return j.contains(t); // should return true.
Answer from Clement P on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ arraylist-contains-java
Arraylist.contains() Method in Java - GeeksforGeeks
December 10, 2024 - Example: Here, we will use the contains() method to check if the ArrayList of Strings contains a specific element. ... // Java program to demonstrate the use of contains() // method with ArrayList of Strings import java.util.ArrayList; public ...
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_arraylist_contains.asp
Java ArrayList contains() Method
The contains() method returns true if an item exists in a list and false otherwise. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ยท If you want to report ...
Discussions

java - Using contains on an ArrayList with integer arrays - Stack Overflow
If you need to check for containment within the Array then you are left with no choice but to iterate through the ArrayList and do the comparison yourself. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Use of contains in Java ArrayList - Stack Overflow
If I have an ArrayList of String forming part of a class in Java like so: private ArrayList rssFeedURLs; If I want to use a method in the class containing the above ArrayList, using More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to use the ArrayList.contain() to check the object in java - Stack Overflow
I am practicing the ArrayList with contains method. For checking the objects in the ArrayList, every time I need to loop through the entire ArrayList using for each loop. Therefore, I am thinking if More on stackoverflow.com
๐ŸŒ stackoverflow.com
How do I create a 2d ArrayList in java?
Fast and easy solution: You can make an arraylist of an object which is of type arraylist More on reddit.com
๐ŸŒ r/learnjava
16
26
June 25, 2020
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ util โ€บ ArrayList.html
ArrayList (Java Platform SE 8 )
October 20, 2025 - Javaโ„ข Platform Standard Ed. 8 ... public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ java โ€บ arraylist โ€บ .contains()
Java | ArrayList | .contains() | Codecademy
February 22, 2024 - It is used to check if the element is present in the specified ArrayList or not. The function returns a boolean value of true if the element is present and false if not. ... Looking for an introduction to the theory behind programming?
Find elsewhere
๐ŸŒ
Vultr
docs.vultr.com โ€บ java โ€บ standard-library โ€บ java โ€บ util โ€บ ArrayList โ€บ contains
Java ArrayList contains() - Check If Contains Element | Vultr Docs
November 27, 2024 - ArrayList<Integer> numbers = new ... is taken. The contains() method in Java's ArrayList provides a simple yet powerful way to check for the presence of an object....
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java collections โ€บ performance of contains() in a hashset vs arraylist
Performance of contains() in a HashSet vs ArrayList | Baeldung
April 4, 2025 - This is an improvement from Java 7 which used a LinkedList for the internal bucket structure. In general, hash code collisions are rare. So we can consider the elements lookup complexity as O(1). Internally, ArrayList uses the indexOf(object) method to check if the object is in the list. The indexOf(object) method iterates the entire array and compares each element with the equals(object) method. Getting back to complexity analysis, the ArrayList.contains() method requires O(n) time.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-the-arraylistcontains-method-in-java
What is the ArrayList.contains() method in Java?
The ArrayList.contains() method in Java is used to check whether or not a list contains a specific element.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ java/util โ€บ java arraylist contains() method
Java ArrayList contains() Method
September 1, 2008 - The Java ArrayList contains(Object) method returns true if this list contains the specified element.
๐ŸŒ
Eduardo Figueiredo
homepages.dcc.ufmg.br โ€บ ~andrehora โ€บ examples โ€บ java.util.ArrayList.contains.11.html
java.util.ArrayList.contains
public class ArrayListDemo { public static void main(String[] args) { // create an empty array list with an initial capacity ArrayList<Integer> arrlist = new ArrayList<Integer>(8); // use add() method to add elements in the list arrlist.add(20); arrlist.add(25); arrlist.add(10); arrlist.add(15); // let us print all the elements available in list for (Integer number : arrlist) { System.out.println("Number = " + number); } // list contains element 10 boolean retval = arrlist.contains(10); if (retval == true) { System.out.println("element 10 is contained in the list"); } else { System.out.println("element 10 is not contained in the list"); } // list does not contain element 30 boolean retval2 = arrlist.contains(30); if (retval2 == true) { System.out.println("element 30 is contained in the list"); } else { System.out.println("element 30 is not contained in the list"); } } }
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 647792 โ€บ java โ€บ check-ArrayList-object-String
how to check if a ArrayList of of object contains a certain String? (Beginning Java forum at Coderanch)
March 25, 2015 - Hi Edin, You can make use of contains(Object o) method in ArrayList which returns true if this list contains the specified element.
๐ŸŒ
BeginnersBook -
beginnersbook.com โ€บ home โ€บ 2013 โ€บ december โ€บ java arraylist contains() method example
Java ArrayList contains() Method example
September 11, 2022 - Last Updated: September 11, 2022 by Chaitanya Singh | Filed Under: java ยท ArrayList contains() method is used for checking the specified element existence in the given list. public boolean contains(Object element) It returns true if the specified element is found in the list else it gives false.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ list-interface-java-examples
List Interface in Java - GeeksforGeeks
contains(Object o): This method takes a single parameter, the object to be checked if it is present in the list. ... import java.util.*; class Geeks { public static void main(String args[]) { List<String> al = new ArrayList<>(); // Adding elements ...
Published ย  1 month ago
Top answer
1 of 2
5

Yes. You need to define your NimPlayer class like this (if you want to compare two NimPlayer objects only by their userName)

package com.example.schooltimetable;

import java.util.Objects;

public class NimPlayer {
  private String userName;
  private String familyName;
  private String givenName;
  private int gamesWon;
  private int gamesPlayed;

  public String getUserName() {
    return userName;
  }

  public void setUserName(String userName) {
    this.userName = userName;
  }

  public String getFamilyName() {
    return familyName;
  }

  public void setFamilyName(String familyName) {
    this.familyName = familyName;
  }

  public String getGivenName() {
    return givenName;
  }

  public void setGivenName(String givenName) {
    this.givenName = givenName;
  }

  public int getGamesWon() {
    return gamesWon;
  }

  public void setGamesWon(int gamesWon) {
    this.gamesWon = gamesWon;
  }

  public int getGamesPlayed() {
    return gamesPlayed;
  }

  public void setGamesPlayed(int gamesPlayed) {
    this.gamesPlayed = gamesPlayed;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;
    NimPlayer nimPlayer = (NimPlayer) o;
    return Objects.equals(userName, nimPlayer.userName);
  }

  @Override
  public int hashCode() {
    return Objects.hash(userName);
  }
}

Now to check if the arraylist contains :

public void showCertainPlayerInformation(ArrayList<NimPlayer> playerList, String inputName)
    {
      NimPlayer n = new NimPlayer();
      n.setUserName(inputName);
      if(playerList.contains(n)){
          ....
          return;
      }
      System.out.println("The player does not exist");
     }
2 of 2
2

You can go to method declaration (CTRL + click on method name) and check its implementation. contains() uses equals() to check whether passed object equals any of the elements or not. And equals() declaration can be found in Object class:

ArrayList Class:

public boolean contains(Object var1) {
    return this.indexOf(var1) >= 0;
}

public int indexOf(Object var1) {
    int var2;
    if (var1 == null) {
        for(var2 = 0; var2 < this.size; ++var2) {
            if (this.elementData[var2] == null) {
                return var2;
            }
        }
    } else {
        for(var2 = 0; var2 < this.size; ++var2) {
            if (var1.equals(this.elementData[var2])) {
                return var2;
            }
        }
    }

    return -1;
}

Object Class:

public boolean equals(Object var1) {
    return this == var1;
}
๐ŸŒ
SpigotMC
spigotmc.org โ€บ threads โ€บ arraylist-contains-method-is-not-working.370503
Solved - ArrayList .contains method is not working | SpigotMC - High Performance Minecraft Community
April 28, 2019 - Hello Everybody, I have been working on a plugin for a server recently and ran into some issues. Theres alot of code to it, so i will just post the...
๐ŸŒ
W3Resource
w3resource.com โ€บ java-tutorial โ€บ arraylist โ€บ arraylist_contains.php
Java ArrayList contains Method - w3resource
Java ArrayList.contains() Method with example: The contains() method is used to determines whether an element exists in a ArrayList object. Returns true if this list contains the specified element.
๐ŸŒ
Programiz
programiz.com โ€บ java-programming โ€บ library โ€บ arraylist โ€บ contains
Java ArrayList contains()
The contains() method takes a single parameter. obj - element that is checked if present in the arraylist ยท returns true if the specified element is present in the arraylist. returns false if the specified element is not present in the arraylist. import java.util.ArrayList; class Main { public ...
๐ŸŒ
Java Development Journal
javadevjournal.com โ€บ home โ€บ arraylist contains() method
ArrayList contains() Method | Java Development Journal
July 20, 2021 - If the ArrayList contains at least one element, then it returns true. Else it returns false. It tries to find out at least one element v such that (o == null ? v == null : o.equals(v)). i.e. if o is null, it returns true only if one element ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ check-if-a-java-arraylist-contains-a-given-item-or-not
Check if a Java ArrayList contains a given item or not
September 13, 2023 - The java.util.ArrayList.contains() method can be used to check if a Java ArrayList contains a given item or not. This method has a single parameter i.e. the item whose presence in the ArrayList is tested.