0
Java help code inserted
I was wondering how to concatenate or replace the letters this regex captures with the same letters but capitalized. Here is the code : https://code.sololearn.com/cqDR58xmUSEp/?ref=app Input : i like big dolls. i don’t like small dolls! do you? yes. wow! Output : I like big dolls. I don’t like small dolls! Do you? Yes. Wow! (don’t mind the example, brain empty) (shoutout to Roland for suggesting that regex)
3 Réponses
+ 1
String result = matcher.replaceAll(mr -> mr.group().toUpperCase());
https://code.sololearn.com/cDkI486NNcep/?ref=app
explanation: we can pass a function (lambda) argument to replaceAll, which converts a matchresult to a string for each occurrence
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/regex/Matcher.html#replaceAll(java.util.function.Function)
0
It works! But is the link u shared working? Because I would love to read the explanation, especially since I’ve never come across a lambda expression used like this
0
Yes, the link points to the Java language documentation