• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

method split() SCJP 6

 
Greenhorn
Posts: 29
Mac Java ME Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


i didnt understand why i have that out put : 4 45
can sommeone explen for me why

s.split("\\.." + "");

she didnt make the out put : 4 x45 a 3
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, the output isn't "4 45" it is this:

4
45



your regex equates to a literal dot, followed by exactly one character. Look at your string, and find everywhere there is a "dot followed by one character", and it should be clear what is going on.

 
adil zahir
Greenhorn
Posts: 29
Mac Java ME Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Look at your string, and find everywhere there is a "dot followed by one character", and it should be clear what is going on.




that mean

"4.x45.a.3"

i will have 4 and x45 and a . the out put will be : 4 x45 a

that what i understand ??!!!
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

adil zahir wrote:

Look at your string, and find everywhere there is a "dot followed by one character", and it should be clear what is going on.




that mean

"4.x45.a.3"

i will have 4 and x45 and a . the out put will be : 4 x45 a

that what i understand ??!!!




No. As fred stated, the delimiter is a literal dot followed by a character.

So, the delimiters are ... ".x", ".a", and ".3". This means that there are four parts ... "4", "45", "". and "". And since the default split() method truncates trailing blanks, you wind up with only the "4", and "45".

Henry
 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
So, the delimiters are ... ".x", ".a", and ".3". This means that there are four parts ... "4", "45", "". and "".
Henry



I think you meant the following?
So, the delimiters are ... ".x", ".a", and ".3". This means that there are four parts ... "4", "45", "", and "".
 
adil zahir
Greenhorn
Posts: 29
Mac Java ME Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Henry Wong and Chan Ag i understand now
 
Ranch Hand
Posts: 68
MyEclipse IDE PHP Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
minor issue, this means that the delimiter right of the expression/pattern will also be considered even in the last position? If not, tokens would be "4", "45", "".
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic