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. Thanks for example..
But I have the same p

View Tutorial          By: Lina at 2009-05-02 13:23:33

2. great explanations.. some important words are miss
View Tutorial          By: Joshua Paul at 2015-04-14 03:43:44

3. IS Java Comm API will supports thw windows?
View Tutorial          By: SAM at 2008-05-29 03:26:44

4. This is very simple and easy to understand.

View Tutorial          By: satish at 2011-12-25 09:03:16

5. can you please e mail me a code about hotel reserv
View Tutorial          By: princeton at 2008-09-19 02:32:13

6. What is the difference between:
CMUsphinx4-

View Tutorial          By: Netrika at 2011-11-26 19:55:07

7. I am able to iterate the list.Now i want to print
View Tutorial          By: akanksha at 2012-09-26 05:25:12

8. Just what i was looking for. tku.
View Tutorial          By: Chow Lim at 2008-03-21 01:46:52

9. Basic Example to undestand java literal persons
View Tutorial          By: Sajid mestri (maha,sangli) at 2010-10-30 00:44:44

10. good understandability code
View Tutorial          By: Raja Mahendra Kumar at 2009-03-05 03:11:26