Reputation: 13
I am trying to practice identifying whether or not a code is valid just by looking at it. I can't find anything about split method implementation that looks like this, and I want to know why.
String[] names = "flowers,are,pretty".split(",",0);
Upvotes: 0
Views: 41
Reputation: 357
This is a valid statement
String[] arr = "flowers,are,pretty".split(",",0);
System.out.println(Arrays.toString(arr));
There is no need of specify limit 0 in the context . Just can use
String[] arr = "flowers,are,pretty".split(",");
Upvotes: 1
Reputation: 50776
String
has a split()
overload that takes an int
parameter, documented here. Calling it with 0 is equivalent to calling the single-parameter overload.
Upvotes: 0
Reputation: 4135
This is valid.
String[] names = "flowers,are,pretty".split(",",0);
for(int i=0;i<names.length;i++)
System.out.println(names[i]);
For more info visit Java docs
Upvotes: 1