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. SMSC number is the sms center no. put the sim to a
View Tutorial          By: Java MAn at 2012-01-28 19:08:23

2. dear sir, plz answer my following questions:

View Tutorial          By: hawa at 2012-01-29 08:29:39

3. explaination is very good ,(lucid and succinct app
View Tutorial          By: shailendra singh at 2010-06-08 11:24:29

4. Enough to understand basic concept.Thanks.
View Tutorial          By: Jyothylakshmy P u at 2012-09-18 05:35:48

5. Can we use the if sttmt l;ike this::
if (a

View Tutorial          By: Anubhav at 2010-11-14 08:15:04

6. this code works for incoming call but not for inco
View Tutorial          By: iman at 2013-08-20 16:21:48

7. MSComm1.Settings="9600,n,8,1"

View Tutorial          By: ali at 2012-02-25 21:52:21

8. Hi DILIP !
Can you plz help me I have an ex

View Tutorial          By: Bull at 2012-01-25 16:16:36

9. Very nice tutorial :)

I have teste

View Tutorial          By: yannoo95170 at 2015-06-18 00:30:26

10. Just what i was looking for. tku.
View Tutorial          By: Chow Lim at 2008-03-21 01:46:52