Memory issues with substring [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How does substring method work internally and how can it create memory issue ?
How can we solve it?

Prior to Java 7 udate 6, substring used to return a view on the original string. So imagine you had a String of 1,000,000 characters and called s.substring(0, 1) because you are only interested in the first character, the original string would have stayed in memory.
Since Java 7u6 substring returns a new string which prevents that issue.

Related

determining which existing string to point to on creation of new string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
in java if you define a string which containes a array of char that already exist it will be bount to the same refrence which i assumed it scanned the memory from bottom to top to search but on further inspection its the first string initiated with that string even if that string has a "higher" adress so i wondered how the java interperter searches for existing strings
i checked the variable's adress using
System.identityHashCode()
and used a basic string for testing like
"hello"

When to use concat and append? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I started learning java and always had this bugging my mind.
When to use concat() and when to use append() operations.
Do they perform the same operation and what of their return types?
concat():
String has a concat method, string is immutable.
adds a string to another string.
It will create the new object after concatenation is done, since it is a immutable.
append():
StringBuilder and StringBuffer has append method, these two are mutable.
appends a char or char sequence to a string.
It will not create a new object, since it is a mutable one.

Why String method substring() is not in camelCase in Java? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
As per Java's standard we should follow CamelCase. But why String's method substring() is not in camelCase ? Is it for any specific reason or just an mistake from the initial days ?
I'd say because substring is one physical word.
camelCase is used to separate words, substring is not to be intended as Sub String but as Substring... so the convention is respected.

Changing the Lengths of Words in a String - Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am currently writing a game in Java, where words in a string will have to be all changed to equal 5 characters a word.
eg. I am writing in Java
Iamwr iting inJav a
I wonder if anyone knows how I would do this?
First remove spaces between words.
Then split that resulting String to length with 5.
Add a space after every 5 character.

How to access a specific array element in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to define specific numbers out of an array of 52 numbers so I can assign them an image (yes I am creating an applet). I don't think that code is necessary for any of you to answer this question. Any help would be fantastic.
I'm not sure I understand what you're asking. You can set an item in an array this way:
myArray[4] = 52;
That would set array index #4 (remember it's zero based so it's actually the 5th item) to the value of 52. Is that what you're looking for?

Categories

Resources