When it's obvious that you have to do it, just do it without shattering your thoughts over different directions.
Rajshekhar Paul wrote:The below mentioned source is a self created one.
The output is
Number of tokens generated: 5 // line 1
1 // line 3
2
34
56789
My question is regarding the blank line between line 1 and line 3.
Can anyone explain me why it is printed?
Paul Campbell wrote: <= first line is a space because of "a" being the first character
When it's obvious that you have to do it, just do it without shattering your thoughts over different directions.
All code in my posts, unless a source is explicitly mentioned, is my own.
When it's obvious that you have to do it, just do it without shattering your thoughts over different directions.
Ruben Soto wrote:Actually the first token is not a space or a blank line, it is the empty string. What happens is that split() considers a token to be a substring of the input that either ends in a separator, or at the end of the string. Your first token starts at the beginning of the string, but since the first character of the input is a separator, the token will be input.substring(0,0) (which is "")
Rajshekhar Paul: My question is regarding the blank line between line 1 and line 3.
Can anyone explain me why it is printed?
When it's obvious that you have to do it, just do it without shattering your thoughts over different directions.
Abhi vijay wrote:But, If I change the input String to
a1a2a34a56789aaa, still the noof tokens generated is 5. Why so??
Sachin Adat wrote:
Abhi vijay wrote:But, If I change the input String to
a1a2a34a56789aaa, still the noof tokens generated is 5. Why so??
What's the explanation to this?
Trailing empty strings are therefore not included in the resulting array.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rajshekhar Paul wrote:My question is regarding the blank line between line 1 and line 3.
Can anyone explain me why it is printed?
SCJP 6
System.out.print(sa[i]+"\n");
It is this line which is printing a blank space than a "\n" at line 2.
System.out.print("Number of tokens generated:" + sa.length+"\n");
this line has nothing to do with blank line 2.
SCJP 6
SCJP 6
Punit Singh wrote:Just go through split() part, but you will get actual learning by practicals, mocks and discussion from javaranch. Here one thing you would have learned that "a" regex is spliting and counting starting blank space, inner blank spaces but avoiding trailing blank spaces.
Punit Singh wrote:Just go through split() part, but you will get actual learning by practicals, mocks and discussion from javaranch. Here one thing you would have learned that "a" regex is spliting and counting starting blank space, inner blank spaces but avoiding trailing blank spaces.
SCJP 6
Punit Singh wrote:Ohhh, just go for exam, you can learn after your exams also, as we are learning here.
Your learning and knowledge matters more than your exam %.
Punit Singh wrote:Your learning and knowledge matters more than your exam %.
When it's obvious that you have to do it, just do it without shattering your thoughts over different directions.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg wrote:And the day on which I decided that I was ready, I didn't get a voucher and had to wait for extra 1.5 months.
Ankit Garg wrote:And after a certain amount of preparation, you start feeling that SCJP is pushing you back and you have got other things to move on like other certifications or practical studies like Struts etc. So if you feel that the time you want to give SCJP is worth it, then you can wait. But don't waste too much time on it as there are a lot of other things to learn...
Sachin Adat wrote:
Anyway I've bought my voucher and I am not planning to wait till June.........no way, its just TIME_MAX.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
SCJP 5.0 (97%)
SCWCD 5.0 (88%)
SCBCD 5.0(Next..)