• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String.split

 
Eden Landau
Ranch Hand
Posts: 40
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason, I can't seem to get String.split to work for me. What am I doing wrong?

 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eden, on line 10-12 you had declared string as null and therefore if condition will never be true and in else you assign them as "null" hence you got output as null null null. What you want to do?
 
Matthew Brown
Bartender
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you're testing what you think you're testing in those if statements? For example, you set first to null, then check if it's null - unsurprisingly, it is.
 
Eden Landau
Ranch Hand
Posts: 40
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh. Whoopsy, then. Yes, this isn't what I wanted to check. Though, now that I did, I get a ArrayIndexOutOfBoundsException. Why's that?

 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because size of String[] input is 3 and you are accessing index 3. Array index start from 0. Here size is 3 so you can access index from 0 to 2.
 
Eden Landau
Ranch Hand
Posts: 40
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow.
I forgot about that completely! Thank you all very much.
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic