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. Been looking at several website for a clear explan
View Tutorial          By: Jase at 2011-08-09 12:00:10

2. i fixed it already...

how can I get

View Tutorial          By: kathleen ashley at 2010-08-08 04:51:26

3. Very clearly explained...
View Tutorial          By: Bina at 2010-04-08 06:56:37

4. how to solve this while i am running the code it
View Tutorial          By: nikhilmuddasani at 2009-07-23 04:32:31

5. i am getting following error

Error

View Tutorial          By: Pavan at 2009-11-26 21:31:22

6. nice overview on struts.....
View Tutorial          By: priyanka at 2010-08-23 00:13:33

7. i nice programs tks
View Tutorial          By: jai at 2011-05-09 14:09:38

8. good
View Tutorial          By: pardhuman at 2011-06-24 08:18:15

9. gr8 work :)
View Tutorial          By: ahmad at 2011-03-23 01:05:57

10. I do not understand this line:
Map.Entry me

View Tutorial          By: hap Og at 2011-11-03 01:42:33