java how to put a string sentence in a map
Java
Map < String, Integer > map = new HashMap < > ();
Scanner sc = new Scanner(System.in); // used to read user input
System.out.println("Enter a string:");
String sentence = sc.nextLine();
String[] tokens = sentence.split(" "); // split based on space
for (String token: tokens) {
String word = token.toLowerCase(); // case insensitive
if (map.containsKey(word)) {
int count = map.get(word); // get word count
map.put(word, count + 1); // override word count
} else {
map.put(word, 1); // initial word count to 1
}
}
Also in Java:
- Title
- decomposer chaine de caractère java
- Category
- Java
- Title
- enumerated data types in java
- Category
- Java
- Title
- java convert edittext to double
- Category
- Java
- Title
- floor in java
- Category
- Java
- Title
- final variables in java
- Category
- Java
- Title
- FileNotFoundException: properties/fortunes.txt (No such file or directory)
- Category
- Java
- Title
- java integer to binary string
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- creating the functional interface in java
- Category
- Java
- Title
- java function without return
- Category
- Java
- Title
- boolean java.lang.String.equals(java.lang.Object)' on a null object reference
- Category
- Java
- Title
- java setroundingmode
- Category
- Java
- Title
- spigot sounds
- Category
- Java
- Title
- import collections in java
- Category
- Java
- Title
- javadoc reference general toString
- Category
- Java
- Title
- java builder pattern example
- Category
- Java
- Title
- cannot lock java compile cache as it has already been locked by this process
- Category
- Java
- Title
- Java nested array hashcode
- Category
- Java
- Title
- how to break from a loop in java
- Category
- Java
- Title
- binary search java
- Category
- Java
- Title
- java stream order by property
- Category
- Java
- Title
- java string util if empty default
- Category
- Java
- Title
- java how to define a function
- Category
- Java
- Title
- java 11 initialize map
- Category
- Java
- Title
- spigot repeating task
- Category
- Java
- Title
- loop through array java
- Category
- Java
- Title
- if and in java
- Category
- Java
- Title
- how to make javafx full screen default
- Category
- Java
- Title
- Filebody in java
- Category
- Java
- Title
- use regex in if statement java
- Category
- Java
- Title
- teimpo en segundos java
- Category
- Java
- Title
- java is power of 2
- Category
- Java
- Title
- Fab to CircularRevealFrameLayout example
- Category
- Java
- Title
- html top padding
- Category
- Java
- Title
- how to check the lines in a file java scanner
- Category
- Java
- Title
- Matlab java.lang.IllegalArgumentException: Invalid range
- Category
- Java
- Title
- summary of operator java
- Category
- Java
- Title
- java time code
- Category
- Java
- Title
- how to get the width and height of a string in java
- Category
- Java
- Title
- java string replace character at position
- Category
- Java
- Title
- how to copy all files and subdirectories in directory in java
- Category
- Java
- Title
- how to write a perfect shuffle method in java
- Category
- Java
- Title
- list in java
- Category
- Java
- Title
- arraylist remove method java
- Category
- Java
- Title
- java 8 findany on null list
- Category
- Java
- Title
- how to make stage dragable in javafx
- Category
- Java
- Title
- join two lists java
- Category
- Java
- Title
- how to create a draw Rectangle in java
- Category
- Java
- Title
- java string array
- Category
- Java
- Title
- code to include layout from java in android
- Category
- Java
- Title
- spigot heal player
- Category
- Java
- Title
- how to import an arraylist in java
- Category
- Java
- Title
- java string to boolean
- Category
- Java
- Title
- android notification addaction example
- Category
- Java
- Title
- android elevation not working
- Category
- Java
- Title
- java treemap
- Category
- Java
- Title
- Display double in decimal places java
- Category
- Java
- Title
- java string contains char
- Category
- Java
- Title
- java cmd install raspbian
- Category
- Java
- Title
- java clear console
- Category
- Java
- Title
- find length of array java
- Category
- Java
- Title
- Removing DOM nodes when traversing a NodeList
- Category
- Java
- Title
- how to find complement of a number in java
- Category
- Java
- Title
- check if value exists in hashset java
- Category
- Java
- Title
- what is a variable in java
- Category
- Java
- Title
- take a value from keyboard java
- Category
- Java
- Title
- java bubble sort short circuit
- Category
- Java
- Title
- java switch
- Category
- Java
- Title
- java find item in list by property
- Category
- Java
- Title
- in dom parser how to find processing instruction in java
- Category
- Java
- Title
- java comments
- Category
- Java
- Title
- java print treemap
- Category
- Java
- Title
- java while loop break
- Category
- Java
- Title
- init cap java
- Category
- Java
- Title
- system.in example in java
- Category
- Java
- Title
- java array to arraylist
- Category
- Java
- Title
- recursive function for fibonacci series in java javascript
- Category
- Java
- Title
- expression régulière téléphone java
- Category
- Java
- Title
- spark write partitionby
- Category
- Java
- Title
- java script num toSting syntax eror
- Category
- Java
- Title
- java remove first character from string
- Category
- Java
- Title
- refrence xml textfield in javafx
- Category
- Java
- Title
- JavaFX mouse over effe
- Category
- Java
- Title
- java map string to list
- Category
- Java
- Title
- java spring boot json deserialize date inaccurate
- Category
- Java
- Title
- check if string is null or empty java
- Category
- Java
- Title
- java array copy
- Category
- Java
- Title
- send variable intent
- Category
- Java
- Title
- convert localdatetime to localdate
- Category
- Java
- Title
- how to read to into a file in java
- Category
- Java
- Title
- java djikstra's algorithm
- Category
- Java
- Title
- how to import a scanner in java
- Category
- Java
- Title
- java check if file exists
- Category
- Java
- Title
- 2d arrays | java
- Category
- Java
- Title
- isnumber java
- Category
- Java
- Title
- java iterate over list
- Category
- Java
- Title
- partial view tiles spring
- Category
- Java
- Title
- android get sdk version
- Category
- Java
- Title
- write file java
- Category
- Java
- Title
- how to format a double in java to 2 decimal places
- Category
- Java