title: An equals() method that determines two Participants is not working
body: <p>What am I doing wrong?</p>
  
  <p>Question is how I will include an <code>equals()</code> method that determines two <code>Participant</code>s are equal if they have the same values in all three fields?
  Include a constructor that assigns parameter values to each field and a <code>toString()</code> method that returns a String containing all the values.</p>
  
  <pre><code>import javax.swing.JOptionPane;
  import java.util.*;
  
  public class Abc {
  
      private static Ab mini[] = new Ab[2];
      private static Ab diving[] = new Ab[2];
  
      public static void main(String[] args) {
  
          String name = "";
          String add = "";
          int age = 0;
  
          Ab p = new Ab(name, age, add);
          Ab p1 = new Ab(name, age, add);
  
          setParticipant();
          setParticipant1();
  
          displayDetail();
          displayDetail1();
  
          if (p == p1) {
  
              System.out.println("equal");
          } else {
              System.out.println("not equal");
  
          }
  
      }
  
      public static void setParticipant() {
          for (int x = 0; x &lt; mini.length; x++) {
              System.out.println("Enter detail about participant1 " + (x + 1) + "...");
  
              String name = getName();
              String add = getAdd();
              int age = getAge();
  
              System.out.println();
              mini[x] = new Ab(name, age, add);
              //Create the object with the data you collected and put it into your array.
  
          }
      }
  
      public static void setParticipant1() {
          for (int y = 0; y &lt; diving.length; y++) {
              System.out.println("Enter Participant2 " + (y + 1) + "...");
  
              String name = getName();
              String add = getAdd();
              int age = getAge();
              System.out.println();
              //mini[x] = new Ab(name, age, add);
              //Create the object with the data you collected and put it into your array.
              diving[y] = new Ab(name, age, add);
          }
      }
  
      public static void displayDetail() {
          // for (int y = 0; y &lt; diving.length; y++) {
          System.out.println("Name \tAge \tAddress");
  
          for (int x = 0; x &lt; mini.length; x++) {
              System.out.println(mini[x].toString());
              // System.out.println(diving[y].toString());
          }
      }
  
      public static void displayDetail1() {
          System.out.println("Name \tAge \tAddress");
  
          for (int y = 0; y &lt; diving.length; y++) {
              System.out.println(diving[y].toString());
          }
      }
  
      public static String getName() {
          Scanner sc = new Scanner(System.in);
          String name;
  
          System.out.print(" Participant name: ");
          return name = sc.next();
      }
  
      // System.out.print(" Participant name: ");
      // name = sc.next();
      public static int getAge() {
          int age;
          System.out.print(" Enter age ");
          Scanner sc = new Scanner(System.in);
          return age = sc.nextInt();
      }
  
      public static String getAdd() {
          String add;
          Scanner sc = new Scanner(System.in);
  
          System.out.print("Enter Address: ");
          return add = sc.next();
      }
  }
  </code></pre>
  
  
  
  <pre><code>public class Ab {
  
      private String name;
      private int age;
      private String address;
  
      public Ab(String strName, int intAge, String strAddress) {
          name = strName;
          age = intAge;
          address = strAddress;
      }
  
      @Override
      public String toString() {
          return name + " " + age + " " + address;
      }
  
      public boolean equals(Participant value) {
          boolean result;
  
          if (name.equals(name) &amp;&amp; age == value.age &amp;&amp; address.equals(address)) {
              result = true;
          } else {
              result = false;
          }
  
          return result;
      }
  }
  </code></pre>