13011111111
13022222222
13033333333
13044444444
13022222222
13022222222
13044444444
13055555555
13066666666
我想只显示不重复的号码。并打印出来,该用什么方法比较啊?都是string
13022222222
13033333333
13044444444
13022222222
13022222222
13044444444
13055555555
13066666666
我想只显示不重复的号码。并打印出来,该用什么方法比较啊?都是string
"13044444444","13022222222","13022222222","13044444444",
"13055555555","13066666666"};
HashMap hm = new HashMap();
for (int i=0; i<strs.length; i++)
{
hm.put(strs[i], i);
}
Iterator it = hm.keySet().iterator();
while (it.hasNext()) {
String key = (String)it.next();
System.out.println(key);
}
示意代码
try
{
for(int i = 0 ;i < astrData.length;i++)
{
if(hashObj.containsKey(astrData[i])
{
hashObj.put(astrData[i],"1");
}
else
{
hashObj.put(astrData[i],"0");
}
}
for (Enumeration e = hashObj.elements() ; e.hasMoreElements() ;)
{
if (hashObj.get(e.nextElement()).equals("1")
{
// do something you want to do
}
}
}
import java.util.*;
public class Parcel5
{
public static void main(String[] args) {
String[] strs = {"13011111111","13022222222","13033333333",
"13044444444","13022222222","13022222222","13044444444",
"13055555555","13066666666"};
Set set = new HashSet(Arrays.asList(strs));
System.out.println(set);
}
}
还不算浪费的太夸张,但是在搜索的时候速度是非常快的,大多数时候一次就能命中用 ArrayList的话,固然节省一点空间,但是搜索匹配的时候,呵呵,开销太大。
我想去掉那些重复的。该怎么实现?
如果
A
A
B
C
C
输入是 B 的话
那么用我的方法。
如果输入是
A
B
C
的话
用我楼上或者楼下的。