About Question enthuware.ocpjp.v7.2.1413 :
Moderator: admin
-
- Posts: 78
- Joined: Sun Jun 30, 2013 10:04 pm
- Contact:
About Question enthuware.ocpjp.v7.2.1413 :
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.
should the last 3 rows below "Regex Limit"
contain the digit 0
instead of o (which is a lowercase O).
Please confirm.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Sun Nov 17, 2013 12:15 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
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
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
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
Yes, that is correct.
If you like our products and services, please help us by posting your review here.
-
- Posts: 42
- Joined: Mon Jan 20, 2014 2:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
Taking another look at what the Java API documentation says regarding the
method i've faced a difficulty understanding the following words:
Code: Select all
public String[] split(String regex,
int limit)
can anyone explain what does it mean in english of us common people....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.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
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:
HTH,
Paul.
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);
}
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 42
- Joined: Mon Jan 20, 2014 2:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
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:
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:
do they refer by that to the rest of the string that follows the delimiter?a positive- width match at the beginning of the string
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
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.
-
- Posts: 42
- Joined: Mon Jan 20, 2014 2:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
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....
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....
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
Thank you for your kind words We try our best to help our users!
Paul.
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 42
- Joined: Mon Jan 20, 2014 2:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
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??
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??
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
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.
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.
-
- Posts: 25
- Joined: Sat Jun 03, 2017 4:56 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
I am still not fully sure if I understand why the correct answer is
, instead ofA String array containing 3 elements
, despite the fact of this mention in the explanation:A String array containing 4 elements
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.
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
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.
-
- Posts: 25
- Joined: Sat Jun 03, 2017 4:56 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1413 :
You're right, no trailing spaces after the delimiter's last match.
Who is online
Users browsing this forum: Google [Bot] and 104 guests