I'm trying to read a file and store the words from the file into a string array excluding spaces/multiple spaces. E.g. my file has the words "this is a test", the program should store into an array arr ["this","is","a","test"] and also increment a variable called wordCount every time it stores a word into the array.
I understand that i can use
fileContents.split("\\s+")
but that does not increment wordCount each time it adds a word into the array. I'm thinking a for loop will do the job but i don't know how.
Any help is appreciated. Thanks.