Re: split query
Roedy Green wrote:
On Fri, 26 Oct 2007 05:28:22 -0700, Nicole.Winfrey@gmail.com wrote,
quoted or indirectly quoted someone who said :
I'm confused about the split string method in the following cases.
String test = "ABC";
String[] arr = test.split(",");
The usual problem people have with split in this:
The split argument is NOT a simple String, but rather a regex
expression. $ ( ) * + - . < = ? [ \ ] ^ { | } characters have magic
meaning. They need to be quoted when you mean them literally. See
http://mindprod.com/jgloss/regex.html#QUOTING
This baffles people. However, your question
String test = "ABC";
String[] arr = test.split(",");
What's the value of arr? Is it null or it has arr[0] with the value of
"ABC"?
Should be solved easily with a simple experiment.
It baffles me when people ask questions like yours. It would be less
work, less typing and much faster to do the experiment than to post a
question.
I wonder what inhibits people from experimenting.
1. too many Star Trek episodes where computers explode given the
"wrong" inputs.
Hah, hadn't considered that.
2. punishment as a child for asking questions.
3. punishment as a child for curiosity.
me thinks 2 and 3 amount to the same thing.
4. lack of confidence in your ability to perform experiments or lack
of confidence in the generality of experimental results. You prefer
the authority of another human.
I'm mostly self taught. I always experimented with everything, except
when I *first* started learning about multithreaded programming. I had
heard so many people say that its so difficult to get right, and that
the code could appear to work, but not be "correct". This put me off of
the subject for a while until I realized that there was a finite
(actually small) set of rules which you could reason with. This gave me
the ability to "mentally" experiment with such scenarios.
Experimentation is definitely an invaluable process.
I recall teaching a computer course to some women reentering the work
force as part of a government program. I asked them to pound some
random keys to prove to themselves the computer would not explode. I
meant this as a joke, and to ease the fear of making mistakes.
One woman asked "Which key should I hit". I said, "Any you like..
Close your eyes. Just hit any keys you like."
She burst into tears. She then reported me for abusing her by giving
her inadequate direction on what to do.
This sounds like an exaggeration, but I believe it. Many of my past
students have known the solution to a problem, but wouldn't attempt it
until I told them it was correct.
If someone has to tell you that you're correct, then you'll never
produce anything original.
She was an extreme example of someone afraid to experiment, someone
terrified of making a mistake or doing something without explicit
permission.
At the opposite end are kids who are itching to press every button to
see if they can figure out what it does.
The kindest thing a parent can do is avoid squashing his children's
curiosity. That was one thing my parents did well.
Agreed, There is a fine line between protecting the wellbeing of your
children and possessions, and causing harm in the form of fear of
experimenting.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>