I have c# code which is
var matches = Regex.Split(sentence.ToLower(), "\\b").Intersect(keyword)
string matchWord= String.Join(" ", matches);
int countWord = Regex.Matches(matchWord, @"[A-Za-z0-9]+").Count;
this code will match the matches word and count it.
How do I convert it to java?
i want to match sentence with keyword and the output will be the keyword that matches.
example :
keyword : "buy", "want", "sell"
input : I want to buy some apple.
output : buy want
output2 : 2
What I have tried:
List<String> keyword = Arrays.asList("word1", "word2", "word3");
Scanner in = new Scanner(System.in);
String sentence = in.nextLine();
String patternString = "\\b(" + StringUtils.join(keyword, "|") + ")\\b";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(sentence);
the .join part is error and i don't know why. It said "cannot find symbol" when I hover over it.
i have no idea how to convert .count into java, because all I know for regex fuction is boolean String.Matches().