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. Thank you......
View Tutorial          By: Suvadip at 2013-04-19 05:11:51

2. main method's return type is void .how main methad
View Tutorial          By: sayyed moin at 2015-09-07 08:55:33

3. Good Explanation.
View Tutorial          By: Ashishkumar Haldar at 2013-01-03 11:47:25

4. thanks a lot that helped.. =D
View Tutorial          By: Karthik at 2008-11-16 02:27:53

5. hi....I have a project, and need help please. I ne
View Tutorial          By: kelvin65 at 2009-05-25 10:03:07

6. hey good code woww. this code lot of help me much
View Tutorial          By: vaibhav malpani at 2015-03-25 05:48:50

7. Hello,

When I put the source code i

View Tutorial          By: Pascal at 2013-03-25 09:12:47

8. I didnt get the use of public Sting toString().. I
View Tutorial          By: Pradesh at 2010-05-06 05:38:23

9. simple way friends:
public class palindrome

View Tutorial          By: Manoj at 2013-01-07 02:18:00

10. Sir, I need to use MS Access as a database in java
View Tutorial          By: John Moses at 2012-03-31 00:20:38