Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Question About Regex

$
0
0
So I was reading through the java API on oracle just to learn some new stuff and I stumbled upon the StringBuilder class. I did some research on it and noticed many people used it to count words in a String like so.
String str = "I am a good boy";
String[] words=str.split("\\s+");
System.out.println(words.length);

I was looking at split() and saw the parameter "\\s+". What does that mean? I tested the code and it somehow magically counts the words correctly but baffled me as to how. Any explanations would be great. Thanks!

*Edited: misleading title renamed

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>