"Aku arep menehi pitutur marang kowe carane nggabungake senar. Proses gabung utawa gabung senar asring diarani nggunakake tembung cekak 'concatenation'. Penyayang kucing bakal gampang ngelingi: con-Cat-en-Nation. I aku guyon ."
"Aturan kanggo nggabungake strings prasaja. Yen kita 'nambah' (+) string lan liya-liyane, banjur 'soko liya' implicitly diowahi kanggo string liwat toString () cara ."
"Saiki kowe ngomong karo aku?"
"Oke, aku bakal nerangake kanthi cara sing luwih gampang. Yen ditambahake string, angka lan kucing, banjur nomer lan kucing kasebut bakal diowahi dadi string. Iki sawetara conto:"
Kode | Kode sing padha |
---|---|
|
Cat cat = new Cat(); String s = cat.toString(); String text = "The cat is " + s; |
|
int a = 5; String s = Integer.toString(a); String text = "a is " + s; |
|
int a = 5; String s = Integer.toString(a); String text = s + "a is "; |
|
Cat cat = new Cat(); String s1 = cat.toString(); String s2 = Integer.toString(a); String text = "The cat is " + s1 + s2; |
|
Cat cat = new Cat(); String s1 = cat.toString(); String s2 = Integer.toString(a); String s3 = Integer.toString(a); String text = s3 + "The cat is " + s1 + s2; |
|
Program ora bakal kompilasi! Operasi tambahan dieksekusi saka kiwa menyang tengen, supaya kita entuk: Yen kita nambah kucing menyang nomer, ora ana konversi senar otomatis. String text = (((cat + a) + "The cat is ") + cat) + a; |
|
Cat cat = new Cat(); String s1 = cat.toString(); String s2 = cat.toString(); String s3 = Integer.toString(a); String s4 = Integer.toString(a); String text = s1 + s3 + "The cat is " + s2 + s4; |
"Wektune wis teka kanggo nindakake sawetara tugas saka Diego."
GO TO FULL VERSION