Which is the most efficient way of creating a string object in java? String s="helo";
or String s=new String("helo");
in terms of memory usage?
Thanks in advance...
fardoonmuhafiz -11
Light Poster
Recommended Answers
Jump to PostString objects are immutable and you can always reuse something that is immutable because you know that it isn't going to get modified. When you are writing "String s = new String("hello");", you are creating an unnecessary object; not only that it is also inefficient cause objects creation itself is. …
All 4 Replies
peter_budo 2,532
Code tags enforcer Team Colleague Featured Poster
verruckt24 438
Posting Shark
peter_budo 2,532
Code tags enforcer Team Colleague Featured Poster
fardoonmuhafiz -11
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.