lets say i input : ‘dog is mammal’
i would like to search for this sentence in a text document. How do i do this in java ?
System.out.println("Please enter the query :");
Scanner scan2 = new Scanner(System.in);
String word2 = scan2.nextLine();
String[] array2 = word2.split(" ");
this code snippet accepts the string ‘dog is mammal’ and process each tokens separately.
For example : ‘dog is mammal’
dog
>
>
is
>
>
mammal
>
>
i would like to process the input as
dog is mammal
>
>
I doesnt want it to process it separately. I wanted it to process it as a single string and look for matches. Can anyone let me know where i am lacking ?
If you want to process the String as a single piece of text, why split up the string into words. I would just use the original
word2you have which is the whole text AFAICSEDIT: If I run
I get
The input is not broken up by word.