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. This example has helped me a lot.! kudos to the wr
View Tutorial          By: Disha Sareen at 2014-12-24 09:30:12

2. I need to know the parameters that we need to pass
View Tutorial          By: puru at 2008-09-08 00:33:46

3. The result shown in the left shift is wrong...
View Tutorial          By: krishnalal.K.K at 2008-05-21 03:05:07

4. Gracias.
View Tutorial          By: maiki at 2015-03-05 15:20:05

5. required the flag set loop stutruce .............
View Tutorial          By: savita at 2013-05-12 04:52:30

6. #include<stdio.h>
void main(){

View Tutorial          By: niru at 2012-07-21 07:26:27

7. thanks or the infromation about switch statement
View Tutorial          By: mikko at 2008-09-01 23:48:44

8. Hi Ramalak, I am suffering with the same error as
View Tutorial          By: Divya at 2008-11-06 22:46:12

9. Following line
if (strcmp(dp->

View Tutorial          By: Sebastiaan Jaarsma at 2012-12-24 19:28:43

10. very good helped me a lot
View Tutorial          By: Swaran at 2009-12-30 09:51:36