Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

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

Go down

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

Post  Admin 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

https://codefornongeek.forumotion.com

Back to top Go down

Back to top

- Similar topics

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