title: Java - make relation between Object list and Hashtable?
body: <p>Is it possible in java to make a relation between Object list and Hashtable.</p>
  
  <p>For example I have this code:</p>
  
  <pre><code>//For list
  MyClass1 obj1 = new MyClass1();
  MyClass2 obj2 = new MyClass2();
  List&lt;Object&gt; list = new ArrayList&lt;&gt;();
  list.add(obj1);
  list.add(obj2);
  
  //For Hashtable
  int first = 10;
  String second = "something";
  Hashtable&lt;String, Object&gt; hash = new ArrayList&lt;&gt;();
  hash.put("1st", first);
  hash.put("2nd", second);
  </code></pre>
  
  <p>Now how can make relations like that:</p>
  
  <p><code>list.get(0)</code> would be related with hash record => <code>{"1st", first}</code> and</p>
  
  <p><code>list.get(1)</code> would be related with hash record => <code>{"2nd", second}</code>?
  So for example later if I would got <code>list</code>, I could see that it's related with specific hash record?</p>
  
  <p>P.S. I tried approach like this:</p>
  
  <pre><code>List&lt;Hashtable&lt;Object, Hashtable&lt;String, Object&gt;&gt; list = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>But then I figured, that my key in first Hashtable sometimes could be the same, what I mean for example there could be such relations:</p>
  
  <pre><code>obj1 related with {"1st", first} 
  </code></pre>
  
  <p>and then </p>
  
  <pre><code>MyClass1 obj3 = new MyClass1();
  obj3 related with {"2nd", second}
  </code></pre>
  
  <p>So then I would have the same key for another record, so it overwrite the old one (and also I have overridden <code>equals</code> and <code>hashCode</code> methods, to be able to use objects as keys, but this one gives the problem as for this reason I can't use it as keys as these keys would be treated as the same).</p>
  
  <p><strong>Update:</strong></p>
  
  <p>To make it more clear.
  For example I have created two same objects (relatively speaking).</p>
  
  <pre><code>MyClass1 obj1 = new MyClass1("name");
  MyClass1 obj2 = new MyClass1("name");
  </code></pre>
  
  <p>Now I need one object to be related with one Hashtable record, the other object with another Hashtable record.
  So if I use something "obj1 show me Hashtable record you have relation with", and it would return Hashtable record it was related (as showed above). And I have a problem relating these objects using maps, because these objects have same parameters (so in Hashtable, these keys would be treated as the same key and would overwrite the other?).</p>
  
  <p>I figured I could do something like this:</p>
  
  <pre><code>List&lt;List&lt;Object&gt;&gt; final_list = new ArrayList&lt;&gt;();
  List&lt;Object&gt; row = new ArrayList&lt;&gt;();
  Hashtable&lt;String, Object&gt; myHash = new Hashtable&lt;String, Object&gt;
  </code></pre>
  
  <p>So then:</p>
  
  <pre><code>myHash.add("1", "something");
  myHash.add("2", 10);
  row.add(obj1);
  row.add(myHash);
  final_lit.add(row);
  </code></pre>
  
  <p>This one kinda works, but it does not really look good as I need to treat first value from list as special, because it is one kind of Object and the rest are Hashtables.</p>