• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String.split()

 
Vigneshwari Chandrasekaran
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


While running this code, I am getting 4 as output. I thought the length will be 3.
Can anyone explain why it is 4?
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vigneshwari Chandrasekaran wrote:

While running this code, I am getting 4 as output. I thought the length will be 3.
Can anyone explain why it is 4?


Hint: if you print out what the four components are, can you decipher on how the splitting is happening?
 
Vigneshwari Chandrasekaran
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried! the output was
3 empty strings and 1 string "bb"
No clue how it is working?
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if this gives you a clue:
 
Vigneshwari Chandrasekaran
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah thank you so much!!
 
Zhenyi Luo
Ranch Hand
Posts: 33
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also be careful when str = "bbaaaaaaaaa"

s.length will be 1
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic