Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Varuna Seneviratna

Ranch Hand
+ Follow
since Jan 15, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
21
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Varuna Seneviratna

Campbell Ritchie wrote:

Varuna Seneviratna wrote:. . . Are they are the same?

Look at their documentation.

. . . What line 29 does is compare the last character in the subStr for alphabetical order with a character in the string that's currently going through the loop.

That doesn't add to the explanation, I am afraid.



This is line 29

What line 29 does is check for alphabetical order the last character in the subStr against a character in the string.  The character of the string which is being compared is the character currently going through the loop to be checked for alphabetical order.

The Documentation for String.isEmpty says Returns true if and only if the length() is 0 and for String.isBlank() says Returns true if the string is empty or contains only whitespace codepoints,otherwise false.  Thanks, Campbell

At the time I didn't know whether for whitespace the length() is 0 or not.  The length() is not 0 for whitespace, isn't it? and isEmpty() returns false for whitespace. I was not sure how both methods work at the time, that's why I included them both

Maybe the description I gave is confusing what about the following

3 weeks ago

Campbell Ritchie wrote:Please don't edit old posts; that makes the thread difficult to follow and makes the line numbers appear wrong. I am refusing the first edit.

Please post the cleaned up code as a new post.




I was responding to your reply. This is your reply I was referring to.

Campbell Ritchie wrote:Please explain what you are looking for. I can see, “abcdef,” which I think is an “unbroken alphabetical” substring, and I can also see, “bd'” which I think probably isn't “unbroken alphabetical”.
Please only post the code you are actually running; there is no point in posting commented‑out code. That makes the code very difficult to read.
Please format and indent the code correctly.
After an isBlank() call, there is no need for an isEmpty() call (line 24).
Line 29 is confusing. It looks as though you had stumbled upon a very inefficient way to iterate the String.

3 weeks ago

Carey Brown wrote:I don't understand why you are going through all those painful steps with sub-strings. You could more easily use two indexes into the input String: begin and end. Increment these as needed and use charAt(idx) to compare the characters. The longest distance between begin and end would be your answer.



Can you please explain what you mean in

You could more easily use two indexes into the input String: begin and end. Increment these as needed and use charAt(idx) to compare the characters.



How to use two indexes into the input String?
3 weeks ago
Carey Brown

Huh?
Line 2 is
i = j;



Line 2 was
        This is just a test I ran to check if the program works correctly if the whole string is alphabetical
3 weeks ago
@CareyBrown
                        Line 2 is a test to see how the program works if the whole string is alphabetical
3 weeks ago
@NormRadder
                       Line 34 is finalStr = "";
                       Line 41 is subStr = "";

        Why do you say they are redundant?

       

Use the String class's valueOf method on line 42 to convert a char to a String


                          Line 42 is
                                            The character in s.charAt(i) gets concataneted to the subStr. So why do you say to use the valueOf() of the String class to convert char to String?

@CampbellRitchie
                                 

After an isBlank() call, there is no need for an isEmpty() call (line 24).


                                               Are they are the same?
                             

 Line 29 is confusing.


                                            Line 29 is
                                                      What line 29 does is compare the last character in the subStr for alphabetical order with a character in the string that's currently going through the loop.
3 weeks ago


Can the code above be improved? What it does is, traverse through an unordered string, find the longest hidden alphabetically ordered string and print it.
3 weeks ago
@Tim Holloway,
                 Thanks, Tim.

So it's really a matter of ensuring that your local system preferences are set up compatibly.



In fact, what made me play games at the code point level is to understand how encoding and decoding translation works. How to determine whether the local system preferences are set up compatibly?  And how is it possible to determine whether the issue is a coding issue or that the font doesn't contain glyph definitions for the Unicode characters? By reading a Unicode code point how to determine where the code point lies within Unicode? In UTF-8 or UTF-16?

Java works with Unicode and only when you set up a print stream with code translation (for example, to ISO-8990-1) will there be a coding issue.


I will try to find out answers to these questions and let you know if I succeed.
1 month ago
I just tried out printing Unicode in jshell and, some did work out and some didn't. I wanted to find out how to be able to print any Unicode codepoint to character form or human readable form. This printing was done in the Windows command line.
1 month ago
How to convert Unicode code points to characters and print using System.out.println(). The emojis at https://home.unicode.org/ cannot be printed. When tried to print, a question mark was the output. Does the encoding of System.out.println() have to be changed?

1 month ago

Campbell Ritchie wrote:Try "\\s+" to split on whitespace (any positive number of characters).



I think by a 0-length String you mean a String without even a space. As this example illustrates . Do you, by a 0-length String, mean a String type but with no space, whitespace or any other character. It is not practically possible to have a 0-length String within a String

In the example "KRE 2017 1 3 0 34 27 2017.005544 424.306 424.28 0 1 N 172 10 2954 F", between 424.28 and 0, there is a space. If there is an 0-length String, How can a space be displayed?

What is meant by "any positive number of characters"? Does an 0-length string fall to the category of "any positive number of characters"





Why doesn't the output of the above example, provided that the "\\s" splits on any positive number of characters, be the same as in the following example. (Why aren't the delimiters displayed in the output of the above)

1 year ago
Actually what happens when splitting  If you split using  then the result is .

When is split using the result is . In first occurrence of "o" the string is split between "b" and "o:and:foo" then when "o" is encountered for the second time "b" and "o:and:foo" is built into {b", "", ":and:foo} .

Why does an empty string gets constructed?
1 year ago
The documentation at https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String) illustrate six examples. From the six examples, how could the sixth example be explained. Why does a space " " come as part of the result. If two equal characters are placed adjecently, then a space comes as a part of the result(array). How to explain this splitting?

The string "boo:and:foo", for example, yields the following results with these parameters:

Regex Limit Result
: 2 { "boo", "and:foo" }
: 5 { "boo", "and", "foo" }
: -2 { "boo", "and", "foo" }
o 5 { "b", "", ":and:f", "", "" }
o -2 { "b", "", ":and:f", "", "" }
o 0 { "b", "", ":and:f" }

1 year ago
Using documentation how can this be understood? By looking at the documentation at https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html#close-, How could this be understood?
1 year ago
Why nextLine() results in a nosuchelementexception when two pipes to System.in are opened and then if one is closed?

1 year ago