Store web links in a file. How to find top 20 links

View previous topic View next topic Go down

Store web links in a file. How to find top 20 links

Post  Admin on Wed Aug 24, 2011 11:56 am

public static void findlinks(String[] str){
Hashtable<String> hash=new Hashtable<String>();
for(int i=0;i<str.length();i++){
if(!hash.contains(str[i])){
hash.put(str[i],new Integer(0));
}
else{
int temp=hash.get(str[i]).intvalue();
hash.put(str[i],new Integer(temp+1));
}

}
MyComparator my=new MyComparator();
Object[] arr=hash.entrySet.toArray();
Array.sort(arr,my);
for(int j=0;j<20;j++){
System.out.println("This "+j+" 's link is "+arr[j]);
}

}
}

class MyComparator implement Comparator{
public int compare(Object o1, Object o2){
if(((Integer)(Map.entry)o1.getValue()).intValue()>((Integer)(Map.entry)o2.getValue()).intValue())
return 1;
else if(((Integer)(Map.entry)o1.getValue()).intValue()<((Integer)(Map.entry)o2.getValue()).intValue())
return -1;
return 0;
}
}

Admin
Admin

Posts : 131
Join date : 2011-08-16

View user profile http://codefornongeek.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum