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



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. <%!
DateFormat date = DateFormat.getDat

View Tutorial          By: saifuctg at 2011-12-30 22:24:54

2. Its working perfectly for me.Thanks so much for pr
View Tutorial          By: Sunpenn at 2009-10-13 00:53:09

3. Can anybody explain me what are the minimum settin
View Tutorial          By: Ramesh at 2010-02-25 10:28:42

4. i want to SCJP exam ,tell how to apply for this ex
View Tutorial          By: PRABAKARAN at 2013-07-16 13:32:50

5. Hello to Every one!! :-),HERE I'AM NOT WRITING A C
View Tutorial          By: Pulkit Malviya at 2012-08-26 14:56:18

6. HI.KEEP ME ON WORK I HAVE MASTER PROGRAMMING C++ <
View Tutorial          By: NINHNGUYEN at 2011-06-19 12:54:20

7. Now what the hell does all this mean???
To

View Tutorial          By: Søren at 2011-09-22 03:13:53

8. Hi, I am new to J2ME and just recently i created a
View Tutorial          By: andre at 2011-08-02 22:57:05

9. can we use if statment with swich,,,!!!
View Tutorial          By: dena at 2011-07-09 13:52:27

10. Very nicely explained, especially the step-by-step
View Tutorial          By: Kaushik at 2012-09-20 04:14:21