Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class StringCounter {
- private LinkedList<Integer> list = new LinkedList<>();
- public StringCounter(LinkedList<Integer> list) {
- this.list = list;
- }
- public static void main(String[] args) {
- HashMap<String, Integer> dictionary = new HashMap<String, Integer>();
- List<String> textFileList = Arrays.asList("Test.txt", "Test2.txt");
- try {
- Dictionary reader = new Dictionary(dictionary);
- for (String text : textFileList) {
- reader.fileScanner(text);
- }
- Scanner textFile = new Scanner(new File("Test4.txt"));
- ArrayList<String> file = new ArrayList<String>();
- while(textFile.hasNext()) {
- file.add(textFile.next().trim().toLowerCase());
- }
- for(String word : file) {
- Integer dict = dictionary.get(word);
- if (!dictionary.containsKey(word)) {
- dictionary.put(word, 1);
- } else {
- dictionary.put(word, dict + 1);
- }
- }
- textFile.close();
- } catch(FileNotFoundException e){
- e.printStackTrace();
- }
- Vector<Integer> vec1 = new Vector<>(dictionary.values());
- for (Integer count : vec1) {
- System.out.println(count);
- }
- }
- }
Add Comment
Please, Sign In to add comment