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. i would like to ask that what is the history of a
View Tutorial          By: Ankit at 2011-02-07 09:56:21

2. if(isset($_POST["check1"]=="1"
View Tutorial          By: krunal at 2012-11-22 10:30:19

3. plz show me my answers
View Tutorial          By: Debnita Saha at 2010-05-01 05:15:16

4. How to use it
View Tutorial          By: Ted at 2011-12-23 07:23:20

5. hello everyone

i want to implement

View Tutorial          By: Prateek at 2010-09-05 00:40:57

6. how to create inode address using c++
View Tutorial          By: pooja at 2014-06-24 05:50:33

7. i need to use sms and to creat using java so it is
View Tutorial          By: Abdulkerim at 2009-09-07 05:29:15

8. nice code. code is running perfectly. but my probl
View Tutorial          By: Avinash at 2013-01-28 07:30:19

9. There is possible to include 2 conditions in for l
View Tutorial          By: aarthi at 2012-12-10 12:08:50

10. Simpler example:

import java.io.*;

View Tutorial          By: Joseph Harner at 2011-12-04 23:20:48