avatar
h*l
1
May I ask what method is used to copy a String to another?
avatar
s*h
2
use = operator directly ah...

【在 h*****l 的大作中提到】
: May I ask what method is used to copy a String to another?
avatar
g*s
3

it will point to same object lah.use constructor or substring.

【在 s**h 的大作中提到】
: use = operator directly ah...
avatar
s*h
4
oh...I thought it was ok to point to the same object:)

【在 g*s 的大作中提到】
:
: it will point to same object lah.use constructor or substring.

avatar
b*r
5
String s1="abc";
String s2= new String(s1)
then change of s2 will not affect s1
在 huangzl (gossip) 的大作中提到: 】
avatar
s*h
6
String s, t;
s="what are you doing?";
t="what what what";
System.out.println(t);
t=s;
System.out.println(t);
s="1.12.2.2.2.2";
System.out.println(t);
output:
what what what
what are you doing?
what are you doing?
hehe

【在 b****r 的大作中提到】
: String s1="abc";
: String s2= new String(s1)
: then change of s2 will not affect s1
: 在 huangzl (gossip) 的大作中提到: 】

avatar
f*u
7
class Str {
String str;
}
class HelloWorldApp {
public static void main(String[] args) {
Str s=new Str();
Str t=new Str();
s.str="1";
t.str="2";
System.out.println(t.str);
t=s;
System.out.println(t.str);
s.str="3";
System.out.println(t.str);
}
}
The result is:
2
1
3
If u use "=" to assiagn class2 to class1, both 1 and 2 contain the same
reference--point to the same object. This phenomenon is called "aliasing

【在 s**h 的大作中提到】
: String s, t;
: s="what are you doing?";
: t="what what what";
: System.out.println(t);
: t=s;
: System.out.println(t);
: s="1.12.2.2.2.2";
: System.out.println(t);
: output:
: what what what

avatar
w*n
8
hehe, it's now quite complicated.
I prefer the simple solusion. such, barber's.

【在 f****u 的大作中提到】
: class Str {
: String str;
: }
: class HelloWorldApp {
: public static void main(String[] args) {
: Str s=new Str();
: Str t=new Str();
: s.str="1";
: t.str="2";
: System.out.println(t.str);

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。