0

Anyone know how to display the punctuations used in a text area , I used hash map. so here is my code of my hash map
i was also thinking of using linear search and combine a if statement, if it is found display it.
The jta.text(); is the name of my text thing. basically wat i have in my text box.

private void countWords()
    {
        int numwords;
        String text = jta.getText();;
            
    // Create a hash map to hold words as key and count as value
   /Map<String, Integer> hashMap = new HashMap<String, Integer>();

    String[] words = text.split("[ .!?\\n-]");
    numwords = words.length;
    System.out.println("Number of words: " + numwords);
    
    for (int i = 0; i < words.length; i++) {
      if (words[i].length() > 1) {
        if (hashMap.get(words[i]) != null) {
          int value = hashMap.get(words[i]).intValue();
          value++;
          hashMap.put(words[i], value);
        }
        else
          hashMap.put(words[i], 1);
      }
    }

    // Create a tree map from the hash map
    Map<String, Integer> treeMap =
      new TreeMap<String, Integer>(hashMap);

    // Display mappings
    System.out.println("Display words and their count in " +
      "ascending order of the words");
    System.out.print(treeMap);
        
    }

im 1 step away from completing this
see my other full code in some other post

please help

1
Contributor
1
Reply
2
Views
11 Years
Discussion Span
Last Post by pfr
0

oh yes and if anyone know any way to combine equalsIgnoreCase case thing in my hash map, when im doing the Total Words thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.