import java.util.Arrays;
public class Words {
public static void main(String[] args) {
// TODO Auto-generated method stub
String text;
text="aa bb cc dd"
+"ee ff"
+"gg hh";
String[] words=text.split("");
//Arrays.sort(words);
int count=0;
for (String word : words) {
System.out.println("words are-->"+word);
}
}
}
words are-->
words are-->a
words are-->a
words are-->
words are-->b
words are-->b
words are-->
words are-->c
words are-->c
words are-->
words are-->d
words are-->d
words are-->e
words are-->e
words are-->
words are-->f
words are-->f
words are-->g
words are-->g
words are-->
words are-->h
words are-->h
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class Words {
public static void main(String[] args) {
// TODO Auto-generated method stub
String text;
text="aa bb cc dd"
+"aa ee ff"
+"gg hh dd";
String[] words=text.split("");
//Arrays.sort(words);
int count=0;
for (String word : words) {
System.out.println("words are-->"+word);
}
TreeMap<String, Integer> wordList=new TreeMap<String,Integer>();
String thisWord="";
String nextWord="";
for (int i = 0; i < words.length; ++i) {
thisWord=words[i];
count++;
nextWord=words[i++];
if (!thisWord.equals(nextWord)) {
wordList.put(thisWord, count);
count=0;
}
}
//odd
nextWord=words[words.length-1];
if ((thisWord.equals(nextWord))) {
count++;
}
else {
count=1;
}
if (words.length %2!=0) {
wordList.put(nextWord, count);
}
Set set=wordList.entrySet();
Iterator i=set.iterator();
while (i.hasNext()) {
Map.Entry me=(Map.Entry)i.next();
System.out.println(me.getKey()+"; ");
System.out.println(me.getValue()+"; ");
}
}
}
words are-->
words are-->a
words are-->a
words are-->
words are-->b
words are-->b
words are-->
words are-->c
words are-->c
words are-->
words are-->d
words are-->d
words are-->a
words are-->a
words are-->
words are-->e
words are-->e
words are-->
words are-->f
words are-->f
words are-->g
words are-->g
words are-->
words are-->h
words are-->h
words are-->
words are-->d
words are-->d
String[] words=text.split("");
is still missing a space, it should be
String[] words=text.split(" ");
TreeMap<Integer, String> ts=new TreeMap<Integer, String>(theComparator);
TreeMap<Integer, String> tm=new TreeMap<Integer, String>();
TreeMap<String, Integer> tm new T
and then i clicked sontrol space i do not see option of
TreeMap<String, Integer>
as attached. i wonder why it does show that when i click control space