• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Split method

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to every one..
any one help me..
class Test
{
public static void main(String[] args)
{
String a="SDF";
String b[]=a.split(",");
System.out.println("size is----------"+b.length);
}
}
when I run this program I am getting out put as
size is----------1
why I am getting size as 1
I am expecting the output size is----------0
Any one send me the reply as early as possible.
Thanks in advance.
--
Ishmayel.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am expecting the output size is----------0



Basically, when you have no matching delimiters, then there is nothing to split -- the whole string is one field.

Henry
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
split function splits the string into tokens which it identifies by expression given as parameter to split (in your case ,).The whole string as a single token still remains even if there is no separating char in it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic