package com.tools;
import java.util.ArrayList;
public class HashCodeMeaning {
public static void main(String[] args) {
ArrayList list =
new
ArrayList();
int numberExist=0;
for
(int i = 0; i < 10000; i++) {
Object obj=
new
Object();
if
(list.contains(obj.toString())) {
System.out.println(obj.toString() +
" exists in the list. "
+ i);
numberExist++;
}
else
{
list.add(obj.toString());
}
}
System.out.println(
"repetition number:"
+numberExist);
System.out.println(
"list size:"
+list.size());
numberExist=0;
list.clear();
for
(int i = 0; i < 10000; i++) {
Object obj=
new
Object();
if
(list.contains(obj)) {
System.out.println(obj +
" exists in the list. "
+ i);
numberExist++;
}
else
{
list.add(obj);
}
}
System.out.println(
"repetition number:"
+numberExist);
System.out.println(
"list size:"
+list.size());
}
}
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。