I need a pure Java program to search on a given string to "find words near each other" - each-other distance need to be specified. More specifically said :- finds word1 and word2 in any order, as long as they occur within a certain distance of each other.
For example :- to search for a "cancer" and "problems" within 3 words of each other in a given string - if found return "true" else return "false".
String term = "cancer problems"; String text = "doctors found many cancer related chest problems in japan during second world war."; int distance = 3; // distance may vary
I prefer pure Java solution rather regex solution.