fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. String nome;
  11.  
  12. public Ideone(String nome){
  13. this.nome = nome;
  14. }
  15.  
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. Ideone a = new Ideone("AAA");
  19. Ideone b = new Ideone("BBB");
  20. Ideone c = new Ideone("CCC");
  21. Ideone copiaa = new Ideone("AAA");
  22.  
  23. System.out.println("a & b :" + a.equals(b));
  24. System.out.println("a & copia a :" + a.equals(copiaa));
  25.  
  26. List<Ideone> lista = new ArrayList<Ideone>();
  27.  
  28. lista.add(a);
  29. lista.add(b);
  30.  
  31. System.out.println("contains a :" + lista.contains(a));
  32. System.out.println("contains c :" + lista.contains(c));
  33. System.out.println("contains a em copia a :" + lista.contains(copiaa));
  34. }
  35.  
  36. @Override
  37. public boolean equals(Object other){
  38. if (!(other instanceof Ideone)){
  39. return false;
  40. }
  41.  
  42. if (other == this){
  43. return true;
  44. }
  45.  
  46. Ideone temp = (Ideone) other;
  47.  
  48. return (this.nome.equals(temp.nome));
  49. }
  50.  
  51. }
Success #stdin #stdout 0.08s 33924KB
stdin
Standard input is empty
stdout
a & b :false
a & copia a :true
contains a :true
contains c :false
contains a em copia a :true