Note:
If you found all of the a4 values are the same as a1, please change the init value of h4 such as:
static HashMap<String, String> h4 = new HashMap<String, String>([b]1[/b]);
If you found all of the a4 values are the same as a1, please change the init value of h4 such as:
static HashMap<String, String> h4 = new HashMap<String, String>([b]1[/b]);
package test;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
public class Testor {
static Testor t = new Testor();
class T1{
String s;
T1(String pS){
s = pS;
}
@Override
public int hashCode() {
return (int)(Math.random()*1000);
}
@Override
public String toString() {
return s;
}
}
class T2{
String s;
T2(String pS){
s = pS;
}
@Override
public int hashCode() {
return s.hashCode();
}
@Override
public String toString() {
return s;
}
}
static HashMap<String, String> h1 = new HashMap<String, String>(50);
static {
for (int i = 0; i < 20; i++) {
h1.put(String.valueOf(i), String.valueOf(i));
}
}
static HashMap<T1, String> h2 = new HashMap<T1, String>();
static {
Testor t = new Testor();
for (int i = 0; i < 20; i++) {
h2.put(t.new T1(String.valueOf(i)), String.valueOf(i));
}
}
static HashMap<T2, String> h3 = new HashMap<T2, String>();
static {
for (int i = 0; i < 20; i++) {
h3.put(t.new T2(String.valueOf(i)), String.valueOf(i));
}
}
static HashMap<String, String> h4 = new HashMap<String, String>(1);
static {
for (int i = 0; i < 20; i++) {
h4.put(String.valueOf(i), String.valueOf(i));
}
}
public static void main(String[] args) {
Iterator<Entry<String,String>> it = h1.entrySet().iterator();
Iterator<Entry<T2,String>> it3 = h3.entrySet().iterator();
Iterator<Entry<T1,String>> it2 = h2.entrySet().iterator();
Iterator<Entry<String,String>> it4 = h4.entrySet().iterator();
while (it.hasNext()) {
String a1 = it.next().getKey();
T1 a2 = it2.next().getKey();
T2 a3 = it3.next().getKey();
String a4 = it4.next().getKey();
System.out.print(a1 + "|" + a3 + "|" + a2 + "|" + a4 + " ");
}
}
}