title: Determining Class from String representation of an Object
body: <p>Consider I am given an array of <code>Classes</code> and string representation of an <code>Object</code>.  How can I get which <code>Class</code> this <code>Object</code> belongs to?</p>
  
  <p>I thought of this approach but I don't know how to achieve it:</p>
  
  <blockquote>
    <p>Iterating over Class array and then getting all instances of that
    class.Then convert each instance to its String representation and then
    check if it equals given String.</p>
  </blockquote>
  
  <p>The problem I'm having is how do I get all <code>Instances</code> of that <code>Class</code>?
  We can use <code>getInstance()</code> if all are <code>Singleton</code> class but what if not?</p>
  
  <p>Please clarify my if I have any misunderstanding.</p>
  
  <pre><code>import java.util.*;
  
  public class Class_instance {
  
    public static void main(String args[]){
       List&lt;Class&gt; class_list = new ArrayList&lt;Class&gt;();
       Test_class x = new Test_class();
       Test y = new Test();
  
       class_list.add(x.getClass());
       class_list.add(y.getClass());
  
       String ex = x.toString();
       }
  }
  </code></pre>
  
  <p>How to know what class <code>ex</code> represents here?</p>