Lets say I have a char array that contains the sequences of chars: “robots laser car”
I want to search for spaces in this char array in order to identify each separate word. I wanted to do something like this pseudocode below:
for lengthOfArray
if array[i].equals(” “)
doSomething();
But I cant find array methods to that comparison.
It’s not exactly what you’re asking for, but I’ll throw it out there anyway: if you have a
Stringinstead of achararray, you can split by whitespace to get an array of strings containing the separate words.The
\s+regular expression matches one or more whitespace characters (space, carriage return, etc.), so the string will be split on any whitespace.