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. very useful
View Tutorial          By: Ruchika at 2011-07-10 05:15:05

2. Hi all this program is working very fine .... i ha
View Tutorial          By: Ashish at 2009-03-25 04:28:25

3. good but not best
View Tutorial          By: VIVEK at 2010-03-09 03:00:21

4. sir i m getting chat server started bt how a clien
View Tutorial          By: ashu at 2010-11-02 08:13:00

5. sorry i think that's a constructor...just had one
View Tutorial          By: Gautam at 2013-10-14 15:55:14

6. not work
View Tutorial          By: kkbb at 2011-03-12 03:52:06

7. its amazing for me i learn a lot from it thanks..
View Tutorial          By: sufyan at 2014-10-26 14:39:34

8. Hi Mounika, The reason to the problem is that you
View Tutorial          By: Ramlak at 2008-04-26 20:06:21

9. Actually, 120º *is* 2.0943951023931953 radian
View Tutorial          By: Stephen Blythe at 2012-04-02 03:39:03

10. Very new to Java and was hoping you could explain
View Tutorial          By: Confused at 2011-08-16 14:02:06