import java.util.*;
public class Paixu {
public static void main(String[] args) {
Map<String,Integer> table =new Hashtable<String,Integer>();
for(int i=0;i<100000;i++)
{
String a ="a"+new Random().nextInt(30);
if(!table.containsKey(a))
{
table.put(a, 1);
}else
table.put(a, table.get(a)+1);
}
List list =new ArrayList();
int count=0;
Iterator it =table.keySet().iterator();
while(it.hasNext())
{
if(count<10){
String key =(String)it.next();
Integer val =table.get(key);
bijiao ii =new bijiao();
ii.setKey(key);
ii.setVal(val);
list.add(ii);
count++;
}
}
Collections.sort(list);
while(it.hasNext())
{
String key = (String)it.next();
Integer val =table.get(key);
bijiao uu =new bijiao();
if(val>uu.getVal())
{
bijiao pp =new bijiao();
pp.setKey(key);
pp.setVal(val);
list.set(9, pp);
Collections.sort(list);
}
}
for(int t =0;t<10;t++)
{
bijiao yy =(bijiao)list.get(t);
System.out.println(yy.getKey()+"++"+yy.getVal());
}
}
}
|
class bijiao implements Comparable
{
private String key;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
private int val;
@Override
public int compareTo(Object o) {
// TODO 自动生成的方法存根
return 0;
}
}
|
搜索引擎会通过日志文件把用户每次检索使用的所有检索串都记录下来,每个查询串的长度为1-255字节。 假设目前有一千万个记录(这些查询串的重复度比较高, 虽然总数是1千万,但如果除去重复后,不超过3百
最新推荐文章于 2021-07-26 22:15:48 发布