Re: Bug in String's split method???
- From: "Virgil Green" <vjg@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 27 Jun 2005 17:37:11 GMT
castillo.bryan@xxxxxxxxx wrote:
> I was trying to write a utility method that work almost the same as
> the split method on String, that would work with java versions 1.3 or
> less,
>
> using Jakarta's ORO library. I though I implemented it according to
> the javadoc for the split method on String. But the expression
> "".split(",", 0),
> returns an array with 1 element, I was expecting an array with no
> elements.
> The expression ",".split(",", 0) returns an array with no elements.
> Is this a bug or am I reading the docs wrong?
>
> Code:
> String[] result = null;
> result = "".split(",", 0);
> System.out.println(result.length);
> result = ",".split(",", 0);
> System.out.println(result.length);
> System.out.println(System.getProperty("java.version"));
>
> Output:
> 1
> 0
> 1.4.2_06
>
> I thing the output should be:
> 0
> 0
> 1.4.2_06
>From java doc for String.split (asterisks/bold added for emphasis):
The array returned by this method contains each substring of this string
that is terminated by another substring that matches the given expression or
is terminated by the end of the string. The substrings in the array are in
the order in which they occur in this string. *If the expression does not
match any part of the input then the resulting array has just one element,
namely this string.*
--
Virgil
.
- Follow-Ups:
- Re: Bug in String's split method???
- From: castillo . bryan
- Re: Bug in String's split method???
- References:
- Bug in String's split method???
- From: castillo . bryan
- Bug in String's split method???
- Prev by Date: Re: J2SE 1.4.2 or J2SE 5.0?
- Next by Date: Re: Q: const?
- Previous by thread: Re: Bug in String's split method???
- Next by thread: Re: Bug in String's split method???
- Index(es):
Relevant Pages
|