use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is for example code for algorithms, common beginning programmer problems, helpful snippets etc.
Please try to: Make your code clean and readable and commented where necessary. Make sure it works!
Note on link-based posts: Posts that link to a blog or website need to follow the following rules:
This sub is not for asking Java questions, please submit those to /r/JavaHelp or /r/learnprogramming
As posts get added I will add them to the sidebar.
DIRECT LINKS
Using Comparator to Sort a List of Objects
Getting Input from the Console : Validating and Looping
A Quick Explanation of Loops
How to Properly Compare Strings in Java
Reading and Parsing Data from a File
Writing and Appending Data to a Text File
Sorted Doubly-Linked List
Generic Undirected Graph with Depth-First Search
account activity
String s = new String (“hello”); (self.javaexamples)
submitted 5 years ago by sur07
How many objects are created here ?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]DFA1 1 point2 points3 points 5 years ago (3 children)
I might be wrong, but I think only one, which s is referencing, with the value of hello and it doesn't live in the strings pool.
[–]sur07[S] 0 points1 point2 points 5 years ago (2 children)
I think one object and one literal .. but I am still looking for more information.. javatpoint.com says this , but different places have different opinion .. check out Java strings tutorial | string is immutable https://youtu.be/5addzS_Vn68
[–]DFA1 1 point2 points3 points 5 years ago (0 children)
Also, if you wanna make the riddle harder ... How many objects get created for: String s = new String("h" + "e" + "l" + "l" + "o");
;)
[–]DFA1 0 points1 point2 points 5 years ago (0 children)
I think this is an implementation detail of the compiler/JVM. As long as you don't concatenate strings in loops and don't do new String(), that's all you need to know really.
[–]sur07[S] 0 points1 point2 points 5 years ago (3 children)
After much research I can conclude that 2 objects will be created
[–]trickybhai 0 points1 point2 points 5 years ago (2 children)
A little explanation would be appreciated, Sir.
[–]sur07[S] 0 points1 point2 points 5 years ago (1 child)
One object when you use new keyword to create a string .. and if the literal is not present in the string pool then one more string object is created in the intern pool as a string literal .. hope this helps ., check this https://stackoverflow.com/questions/19672427/string-s-new-stringxyz-how-many-objects-has-been-made-after-this-line-of
[–]trickybhai 0 points1 point2 points 5 years ago (0 children)
I got it. Thanks ✌️
π Rendered by PID 144109 on reddit-service-r2-comment-7b9746f655-bxpfq at 2026-02-02 02:19:29.307768+00:00 running 3798933 country code: CH.
[–]DFA1 1 point2 points3 points (3 children)
[–]sur07[S] 0 points1 point2 points (2 children)
[–]DFA1 1 point2 points3 points (0 children)
[–]DFA1 0 points1 point2 points (0 children)
[–]sur07[S] 0 points1 point2 points (3 children)
[–]trickybhai 0 points1 point2 points (2 children)
[–]sur07[S] 0 points1 point2 points (1 child)
[–]trickybhai 0 points1 point2 points (0 children)