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. Hello
I installed Android in eclipse...only

View Tutorial          By: amit kumar at 2012-01-19 11:04:55

2. Thank you very much for such a nice topic
View Tutorial          By: CHANDAN at 2012-11-01 04:40:02

3. the DomParserExample.java shows MAlformedURLExcept
View Tutorial          By: dipesh at 2011-12-09 09:53:46

4. Excelente!!
Justo lo que necesitaba.

View Tutorial          By: Cesar at 2010-01-07 17:40:52

5. javax.microedition.io.ConnectionNotFoundException:
View Tutorial          By: yellaiah at 2014-12-27 05:18:52

6. PROGRAMMING SUPERB
View Tutorial          By: vinay sharma at 2010-10-01 05:16:23

7. Hi i have studied these programs.
but unabl

View Tutorial          By: Karuna at 2008-03-30 08:46:00

8. javax.comm.NoSuchPortException
at javax.co

View Tutorial          By: vijay at 2013-12-03 07:32:38

9. very useful...!
View Tutorial          By: mahesh at 2012-01-06 09:55:59

10. not that much clear exampl.. you should explain it
View Tutorial          By: elangovan at 2010-06-09 02:36:19