Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String[] wordList = fileContents.split("\s");
- ArrayList<String> words = new ArrayList<String>();
- ArrayList<Integer> counts = new ArrayList<Integer>();
- words.add(wordList[0]);
- counts.add(0);
- for (int i = 0; i < wordList.length; i++) {
- String tempWord = wordList[i];
- boolean foundEqual = false;
- int count = 0;
- for(int q = 0;q < words.size();q++) {
- if (tempWord.equals(words.get(q))) {
- foundEqual = true;
- counts.add(q, counts.get(q) + 1);
- }
- }
- if(!foundEqual){
- words.add(tempWord);
- counts.add(1);
- }
- }
- for (int i = 0; i < words.size(); i++) {
- System.out.println(words.get(i) + ":" + counts.get(i));
- }
- this is a test
- this is also a test
- this is the last test
- this:3
- is:3
- a:2
- test:3
- also:2
- the:2
- last:2
- counts.add(q, counts.get(q) + 1)
- words.add(wordList[0]);
- counts.add(0);
- words.add(wordList[0]);
- counts.add(0);
- counts.add(0,1)
- i = 1
- i = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement