Comment on Tutorial - Using StringTokenizer in Java By Emiley J



Comment Added by : Anush

Comment Added at : 2012-07-16 08:30:58

Comment on Tutorial : Using StringTokenizer in Java By Emiley J
@pooja: this method should work, although i'm sure it isn't the most efficient one. str is your string.

public void doIt(String str) {
Hashtable<String, Integer> hTable = new Hashtable<String, Integer>();
String next = null;
StringTokenizer st = new StringTokenizer(str);
while (st.hasMoreTokens()) {
next = st.nextToken();
if (hTable.containsKey(next)) {
hTable.put(next, hTable.get(next) + 1);
} else {
hTable.put(next, 1);
}
}
Collection<Integer> coll = hTable.values();
Object[] integerArray = coll.toArray();
Arrays.sort(integerArray, Collections.reverseOrder());
Set<Object> mySet = new LinkedHashSet<Object>(Arrays
.asList(integerArray));
for (Object i : mySet) {
for (Map.Entry<String, Integer> entry : hTable.entrySet()) {
if (i.equals(entry.getValue())) {
System.out.println(entry.getKey());
}
}
}
}


View Tutorial



Ask a Question

Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Thank you
View Tutorial          By: vbulletincoder at 2011-09-13 13:16:40

2. Hi,
Nice example....it's a good one to impl

View Tutorial          By: Anish at 2009-07-08 00:21:16

3. Hello sir pls send me
com.sun.speech.freet

View Tutorial          By: nikunj at 2011-08-19 06:55:37

4. You are good work ,an axplane is so gread

View Tutorial          By: chetan at 2009-06-08 11:58:51

5. Very nice tutorial. Hi Rintu for attachment u can
View Tutorial          By: ras at 2013-03-14 17:19:47

6. i have to learn java
View Tutorial          By: md arif alam at 2013-04-15 18:30:27

7. hi to all i m getting this error plz solve it and
View Tutorial          By: krishna prasad at 2011-10-28 10:16:26

8. Answer for comment 5
this loop is work infi

View Tutorial          By: salman at 2013-03-10 07:30:53

9. help me in my final project about arrays
View Tutorial          By: grace at 2013-03-13 09:54:11

10. hi!!!!!!!!! MR. RAMLAK will u plz tell the methode
View Tutorial          By: balwant at 2008-11-10 17:19:44