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



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....
I have a problem.
I my

View Tutorial          By: AbhiRules at 2010-08-05 20:55:27

2. I got the sample and the test working. Thanks a lo
View Tutorial          By: Trishul at 2009-10-26 07:32:57

3. #include<iostream>
#include<conio.

View Tutorial          By: Zohaib Farooq at 2011-05-23 12:47:54

4. Good ,I like here&#65281; I send gmail with j
View Tutorial          By: jackhexl at 2009-04-02 03:29:44

5. Nice n simple ex!!!!!!!!!!!!!!!!!!!
View Tutorial          By: Siya at 2010-11-17 07:08:34

6. If the compiler takes care of this pointer implici
View Tutorial          By: Bhanu Noah at 2012-03-15 16:20:05

7. Thanks ,got useful information on toString().
View Tutorial          By: jaffar at 2011-08-01 10:15:04

8. Thanks a lot !
View Tutorial          By: Kalander bava ta at 2012-11-04 08:07:15

9. To DD -

The comment you just posted

View Tutorial          By: Alex at 2011-09-30 10:36:11

10. You are using "this" to start to the thr
View Tutorial          By: sumit at 2014-10-30 08:14:55