I am a bit confused as to what the code below is doing since I get the same results from both
String words = numOfWords.split("\\s+"); String words = numOfWords.trim().split("\\s+");
String.trim() only removes leading and trailing white space characters. Unless numOfWords starts or ends with white space, I would expect them to be the same. For an example where the results differ, you could do something like String words1 = " a b".split("\\s+"); String words2 = " a b".trim().split("\\s+"); System.out.printf("%s %s", Arrays.toString(words1), Arrays.toString(words2)); Which outputs [, a, b] [a, b]
.split will do something like "you, are , a, developer" And the top line is doing that and using Regex to tell where to split the string. The second line of code is doing the same thing with redundancy .
Cant generate java code from wsdl file
Jar with multiple main
EasyMock - mock object returned from new Object
Mockito: how to stub inherited methods
Java Making a Custom Report PDF with iText
Calculations between two integer arrays
how to add utf8 text to image with diffrent ttf fonts?
How is it getting an instantiation error and how to fix it? [Android]
Locations saved in sqlite not shown in list [duplicate]
Array list iterators next and previous not working
Is there a way to control windows in another Java process?
JBoss Singleton Service Example: Does not expose a singleton object
YAML multiple keys with multiple values per element
NullPointerException while calling a method from another class [duplicate]
Cant control JavaFX TitledPane with FXML
how to define hashmap within hashmap using object of other hashmap