title: How to compare the data of two same Objects in Java
body: <p>I have a class </p>
  
  <pre><code>            MyData 
  </code></pre>
  
  <p>and its object </p>
  
  <pre><code>             myData 
  </code></pre>
  
  <p>In that Class MyData .. there are multiple fields </p>
  
  <p>like   </p>
  
  <pre><code>           int id   
  
             String  name 
  
             String desc 
  </code></pre>
  
  <p>etc ..</p>
  
  <p>Now i have two objects of this class ..</p>
  
  <p>Is it possible to check that if the data of these two object are all the same , Like both objects have the same Id ,same Name ,same Desc ... Without checking each and every field of this object ..(i.e without checking the id,name,desc of Each object myself) As there are dozens of fields of this object .</p>
  
  <p>I am using JAVA with GWT</p>
  
  <p>Some implementation i came across.. Not sure if this is some thing possible .valid</p>
  
  <pre><code>    private static String oldSequence = "";
  
      boolean changed(TestSequence sequence) {
          String newSequence = serializeToString(sequence);
          boolean changed = !newSequence.equals(oldSequence);
          oldSequence = newSequence;
          return changed;
  
  
      }
  
      private static byte[] serialize(Object obj) throws IOException {
          ByteArrayOutputStream b = new ByteArrayOutputStream();
          ObjectOutputStream o = new ObjectOutputStream(b);
          o.writeObject(obj);
          return b.toByteArray();
      }
  
      private static String serializeToString(Object obj) {
          try {
              return new String(serialize(obj));
          } catch (Exception ex) {
              return "" + ex;
          }
      }
  </code></pre>
  
  <p>Thanks </p>