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.
Related
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"
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 4 years ago.
Improve this question
The method accepts two strings s1,s2 as parameters and returns the string in the object that is triggered when each instance of string s1 is replaced by s2. otherwise, it will do nothing
for example :
if we have string:"abcdecc" , with parameters s1="cc" and s2="fff"
then the method will return string as : "abcdefff"
replaced s1 with s2
If you have (or can include) Apache Commons library in your project, then I recommend using StringUtils
String result = StringUtils.replace("abcdecc", "cc", "fff");
You can use String.replace() as well but it uses Regex, so in terms of performance StringUtils.replace() is better.
Simply use this as your method:
String replace_method(String s, String s1, String s2){
return s.replace(s1, s2);
}
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'm using Java to implement the Apriori algorithm but one problem exists.
ArrayList<String> l1=new ArrayList<>();//L1
...
ArrayList<String[]> lk1=l1;//Lk-1
Then it warns that: cannot convert from ArrayList<String> to ArrayList<String[]>. How can I solve this problem?
They're different types. Ignore the collection and just look at the underlying type.
String str = "This is a string.";
String[] array = str;
These are two different types, unconvertable, so as T for the collection, the collections are then unconvertable. Very basic concept here.
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.
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 am developing a Java program and I'm meeting cases where I get undecided whether to use the casting a string to integer method, or to use the integer.parseInt method. Is there any clear benefit for either of the two methods?
With 'casting to string method', I mean:
String.valueOf(integer);
As far as I know, it's not possible to cast from a String to an int, so using Integer.parseInt seems like the best option here.
Looking at your edits about using valueOf, perhaps this link may help: Integer.valueOf() vs. Integer.parseInt()