Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. String[] wordList = fileContents.split("\s");
  2.  
  3. ArrayList<String> words = new ArrayList<String>();
  4. ArrayList<Integer> counts = new ArrayList<Integer>();
  5. words.add(wordList[0]);
  6. counts.add(0);
  7. for (int i = 0; i < wordList.length; i++) {
  8. String tempWord = wordList[i];
  9. boolean foundEqual = false;
  10. int count = 0;
  11. for(int q = 0;q < words.size();q++) {
  12. if (tempWord.equals(words.get(q))) {
  13. foundEqual = true;
  14. counts.add(q, counts.get(q) + 1);
  15. }
  16.  
  17. }
  18. if(!foundEqual){
  19. words.add(tempWord);
  20. counts.add(1);
  21. }
  22.  
  23. }
  24. for (int i = 0; i < words.size(); i++) {
  25. System.out.println(words.get(i) + ":" + counts.get(i));
  26. }
  27.  
  28. this is a test
  29. this is also a test
  30. this is the last test
  31.  
  32. this:3
  33. is:3
  34. a:2
  35. test:3
  36. also:2
  37. the:2
  38. last:2
  39.  
  40. counts.add(q, counts.get(q) + 1)
  41.  
  42. words.add(wordList[0]);
  43. counts.add(0);
  44.  
  45. words.add(wordList[0]);
  46. counts.add(0);
  47.  
  48. counts.add(0,1)
  49.  
  50. i = 1
  51.  
  52. i = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement