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. Can u please help me. I run the SerialConnection p
View Tutorial          By: Praseetha.K at 2009-01-23 09:34:35

2. What if the MIDlet has an sms push registry, but o
View Tutorial          By: indra at 2011-07-08 09:21:54

3. Many thanks!
View Tutorial          By: Bego at 2014-07-10 08:48:02

4. hi issac thank you for your sample. can you please
View Tutorial          By: edwin at 2009-05-20 22:04:14

5. what about object bean with view scope ??
View Tutorial          By: abdelaziz akharraz at 2012-10-09 15:06:52

6. Thanks for providing detailed information .
View Tutorial          By: CM Mankar at 2008-03-18 04:37:03

7. Awesome............
View Tutorial          By: Amol at 2011-06-11 05:32:49

8. its a big help!..thankz
View Tutorial          By: mezer at 2013-07-17 05:34:07

9. i m a student of Bahria university,Pakistan.and th
View Tutorial          By: Rao Waseem at 2011-05-14 12:55:53

10. Hi Steven. It looks like your example program does
View Tutorial          By: Ben Hallinan at 2008-04-25 08:36:42