About Question enthuware.ocpjp.v7.2.1413 :

Moderator: admin

Post Reply
ewebxml
Posts: 73
Joined: Sun Jun 30, 2013 10:04 pm
Contact:

About Question enthuware.ocpjp.v7.2.1413 :

Post by ewebxml » Sun May 11, 2014 5:35 pm

For the regex limit columns,
should the last 3 rows below "Regex Limit"
contain the digit 0
instead of o (which is a lowercase O).

Please confirm.

admin
Site Admin
Posts: 8307
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by admin » Sun May 11, 2014 8:34 pm

No, o (lowercase O) is correct. This is taken from http://docs.oracle.com/javase/7/docs/ap ... html#split(java.lang.String, int)

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

lazydoozer
Posts: 2
Joined: Sun Nov 17, 2013 12:15 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by lazydoozer » Mon Oct 27, 2014 7:00 am

Hi

In the example given, is the reason that there is not one more token returned due too "the array can have any length, and trailing empty strings will be discarded."

Thanks

admin
Site Admin
Posts: 8307
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by admin » Mon Oct 27, 2014 12:00 pm

Yes, that is correct.
If you like our products and services, please help us by posting your review here.

Nisim123
Posts: 42
Joined: Mon Jan 20, 2014 2:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by Nisim123 » Thu May 19, 2016 7:17 am

Taking another look at what the Java API documentation says regarding the

Code: Select all

public String[] split(String regex,
                      int limit) 
method i've faced a difficulty understanding the following words:
When there is a positive-width match at the beginning of this string then an empty leading substring is included at the beginning of the resulting array. A zero-width match at the beginning however never produces such empty leading substring.
can anyone explain what does it mean in english of us common people.... :?

admin
Site Admin
Posts: 8307
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by admin » Thu May 19, 2016 8:05 am

Lets say your string is "123456" and you are splitting by "1". You have a match at the beginning itself. Therefore, the resulting array of tokens will have two elements "", and "23456".

You should try out various combinations of this code and verify:

Code: Select all

    String s = "123456";
    String[] sa = s.split("1");
    for(String sas : sa){
      System.out.println(sas);
    }
HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Nisim123
Posts: 42
Joined: Mon Jan 20, 2014 2:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by Nisim123 » Fri May 20, 2016 3:50 am

Thanks, it does help!
So when you say that there is a match at the beginning of the string "1234567" where the delimiter is "1", and the match is in the beginning itself and it is an empty string do you mean it is taken from the position prior to the delimiter? well, if we will count the positions of that given string "1234567" numbering the positions starting from 0, so our delimiter is at position 0 and the empty string comes from what position?
And then when it says in the API:
a positive- width match at the beginning of the string
do they refer by that to the rest of the string that follows the delimiter?

admin
Site Admin
Posts: 8307
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by admin » Fri May 20, 2016 4:43 am

It doesn't matter what position it comes from because the JavaDoc is clear that if there is a match at the beginning, then the first token will be an empty string.
If you like our products and services, please help us by posting your review here.

Nisim123
Posts: 42
Joined: Mon Jan 20, 2014 2:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by Nisim123 » Fri May 20, 2016 6:22 am

Thanks Paul you are great!!

BTW I've read lots of good critics about you guys lately...
mainly at the coderanch site that says your help is essential to pass the certification exam
here is only one of many responses that warmly recommends your services as a must for Oracle candidates....

admin
Site Admin
Posts: 8307
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by admin » Fri May 20, 2016 9:35 pm

Thank you for your kind words :) We try our best to help our users!
Paul.
If you like our products and services, please help us by posting your review here.

Nisim123
Posts: 42
Joined: Mon Jan 20, 2014 2:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by Nisim123 » Sun May 22, 2016 10:08 am

No... you are the one who should be thanked! :-)
and still in our case, i mean in this question, it does not start with a positive- width match,
nor there is a reason for an empty string to be returned, so why does it return an empty string from that position in the string that contains two of the delimiter in a row?? :?

admin
Site Admin
Posts: 8307
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by admin » Sun May 22, 2016 8:37 pm

As per my interpretation of the documentation, there is a match on the first character and so it will return an empty string as the first token.
Regarding the code given in the question, it also behaves exactly as given in the JavaDoc. You have two semicolons together and so it returns and empty token. Now, why it returns an empty token is something that only the API designers can answer. One can certainly design a split method that does behave like this but the JDK designers chose not to. Can't really do much about it :)

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

thodoris.bais
Posts: 25
Joined: Sat Jun 03, 2017 4:56 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by thodoris.bais » Mon Oct 23, 2017 2:01 am

I am still not fully sure if I understand why the correct answer is
A String array containing 3 elements
, instead of
A String array containing 4 elements
, despite the fact of this mention in the explanation:
The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string.

admin
Site Admin
Posts: 8307
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by admin » Mon Oct 23, 2017 6:22 am

You may want to go through the JavaDoc description of the method to understand how it works.
If you like our products and services, please help us by posting your review here.

thodoris.bais
Posts: 25
Joined: Sat Jun 03, 2017 4:56 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1413 :

Post by thodoris.bais » Thu Nov 02, 2017 12:57 pm

You're right, no trailing spaces after the delimiter's last match.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests