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. I really helped with this tutorial.
In case

View Tutorial          By: maya at 2008-07-30 00:35:51

2. The code to show recursion is ok, but the declara
View Tutorial          By: Gaurav at 2010-08-08 01:08:27

3. marvelous
View Tutorial          By: Anon at 2009-02-12 07:51:44

4. this is really cool......
View Tutorial          By: solex at 2009-05-16 04:02:35

5. Excellent information reg the scopes of jsp , plea
View Tutorial          By: venkateshwarreddy suravaram at 2012-01-09 08:34:23

6. Thanks Man , You are Genius i have been looking fo
View Tutorial          By: hamza Ouni at 2015-02-22 13:38:02

7. Hey nice article Brian W. Kernighan and/or Dennis
View Tutorial          By: butt at 2013-01-17 07:12:21

8. Hi, thank you so much for this. I am going to give
View Tutorial          By: Eddie at 2011-02-21 14:10:04

9. @3
argc simply means the argument count.
View Tutorial          By: CDub at 2010-02-22 09:32:54

10. Was useful
View Tutorial          By: Vasan at 2008-06-22 05:04:20