Guest User

Untitled

a guest
Jun 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public class StringCounter {
  2.  
  3. private LinkedList<Integer> list = new LinkedList<>();
  4.  
  5. public StringCounter(LinkedList<Integer> list) {
  6. this.list = list;
  7. }
  8.  
  9. public static void main(String[] args) {
  10.  
  11. HashMap<String, Integer> dictionary = new HashMap<String, Integer>();
  12.  
  13. List<String> textFileList = Arrays.asList("Test.txt", "Test2.txt");
  14.  
  15. try {
  16.  
  17. Dictionary reader = new Dictionary(dictionary);
  18.  
  19. for (String text : textFileList) {
  20. reader.fileScanner(text);
  21. }
  22.  
  23. Scanner textFile = new Scanner(new File("Test4.txt"));
  24. ArrayList<String> file = new ArrayList<String>();
  25.  
  26. while(textFile.hasNext()) {
  27. file.add(textFile.next().trim().toLowerCase());
  28. }
  29.  
  30. for(String word : file) {
  31. Integer dict = dictionary.get(word);
  32. if (!dictionary.containsKey(word)) {
  33. dictionary.put(word, 1);
  34. } else {
  35. dictionary.put(word, dict + 1);
  36. }
  37. }
  38.  
  39. textFile.close();
  40.  
  41. } catch(FileNotFoundException e){
  42. e.printStackTrace();
  43. }
  44.  
  45. Vector<Integer> vec1 = new Vector<>(dictionary.values());
  46.  
  47. for (Integer count : vec1) {
  48. System.out.println(count);
  49. }
  50. }
  51. }
Add Comment
Please, Sign In to add comment