Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update java-quiz.md #1244

Closed

Conversation

KidusMT
Copy link
Contributor

@KidusMT KidusMT commented Mar 6, 2021

update on the java question #7 answer which was a wrong answer.

jshell> str.substring(3,4);
$1 ==> "d"

@rradfar
Copy link
Contributor

rradfar commented Mar 6, 2021

If we try try running this piece of code, it outputs 'abcde'. I believe the reason for this behavior is that the 'toUpperCase()' and 'substring()' methods do not mutate the original string which is what we are printing at the end.

String str = "abcde";
str.trim();
str.toUpperCase();
str.substring(3, 4);
System.out.println(str);  //abcde

If I recall correctly, strings in Java are not mutable so any operation on a string, just returns a new string.

@KidusMT
Copy link
Contributor Author

KidusMT commented Mar 6, 2021

Correctly put @rradfar . I only tested it on jshell for that segment of code. I didn't try to "System.out.println" it.. so yes.correct. Discard this pull request.

@KidusMT KidusMT closed this Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants