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. It too good code
View Tutorial          By: Srinivas at 2011-02-20 03:58:19

2. really great, goes more in depth than cplusplus.co
View Tutorial          By: ss80 at 2008-07-02 06:45:47

3. hi can any one help me how to do basic pc actions
View Tutorial          By: karthikeyan at 2008-03-14 04:18:52

4. thanks for this example
View Tutorial          By: hai at 2011-12-16 05:36:14

5. Please help here...
I tried both 0300460423

View Tutorial          By: Zafar Iqbal at 2013-04-02 20:14:29

6. @Srini

Hi Srini, I can answer your

View Tutorial          By: Sudev Wilson at 2015-04-08 12:23:33

7. Thanks a lot man with the server -side code.
View Tutorial          By: bot at 2011-12-03 15:04:28

8. nice
View Tutorial          By: udhay at 2011-04-01 02:48:25

9. answer of comment No, 17

#include&l

View Tutorial          By: Rashid Jabbar at 2012-09-16 20:23:11

10. simple explanation,.. Nice....
View Tutorial          By: Gopi at 2011-08-19 09:28:47