| Author |
HashSet.addAll Arrays.asList split extra space
|
Miran Cvenkel
Ranch Hand
Joined: Nov 23, 2010
Posts: 138
|
|
Looks , to me like a bug ?
|
Searchable nature photo gallery: http://agrozoo.net/jsp/Galery.jsp?l2=en
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
What are you splitting on? The $ sign, or line end?
|
 |
Miran Cvenkel
Ranch Hand
Joined: Nov 23, 2010
Posts: 138
|
|
The $ sign.
Point beeing:
-->
2$3
[1,2, 2, 3]
you see extra spaces before 2 and 3, which appears from nowhere. Hence I get "duplicate" 2
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4905
|
|
Miran Cvenkel wrote:
[1,2, 2, 3]
you see extra spaces before 2 and 3, which appears from nowhere.
I can guarantee you, it does NOT "appear from nowhere". You also haven't shown us the contents of the original string before the split.
In fact, it might be better to show us a bit more of your code (including the split() call), along with the precise contents of the strings before and after splitting.
Winston
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
Miran Cvenkel
Ranch Hand
Joined: Nov 23, 2010
Posts: 138
|
|
Here you have, test case that proves that something goes wrong in some cases.
Manifestation of that is that some numbers are getting in it with preceding spaces (WRONG), and some are not (OK)
See last out.print, how 13,33 are together and 44,55 pushed to right with space
|
 |
Miran Cvenkel
Ranch Hand
Joined: Nov 23, 2010
Posts: 138
|
|
ahh damn, the secret of this:
is that 13,33 is all together one element. That is why I was confused.
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4905
|
|
Miran Cvenkel wrote:is that 13,33 is all together one element. That is why I was confused.
See how good it is when you have to explain a problem in full to someone else?
FYI, To ensure that your elements don't have any extra whitespace in them, you need to trim your input string first and then use something like
split("\\s*,\\s*")
('split on a comma surrounded by any amount of whitespace'). Viz:HIH
Winston
|
 |
 |
|
|
subject: HashSet.addAll Arrays.asList split extra space
|
|
|