2013年9月15日星期日

java string stringBuffer problem




public class Test{
void Trans(int intIndex, String str, StringBuffer strBuffer)
{
intIndex += 1;
str += '1';
strBuffer.append('1');
}


public static void main(String[] args) {
int intIndex = 100;
String str = "100";
StringBuffer strBuffer = new StringBuffer("100");
Test t = new Test();
t.Trans(intIndex, str, strBuffer);
System.out.println(intIndex);
System.out.println(str);
System.out.println(strBuffer);
}
}

ask why the above output
100
100
1001

------ Solution ------------------------------------ --------
first parameter is the original data , is constant, does not change the value of the original address , the second is the final type , is constant , so the cost will not change , only the the third is a pass into the object object , so you can change its value. . .
------ Solution ---------------------------------------- ----
http://www. ibm.com / developerworks / cn / java / j-lo-processthread / index.html processes and threads do not understand the process


------ For reference only ---------------------------------- -----
intIndex is shaped relationship between the parameter and argument will not change
str is a string, immutable
strBuffer the append method behind the increase in the string string
------ For reference only ---------------------- -----------------
easiest to understand is that the first and the second argument is the value, and the third argument is the reference
------ For reference only ---------------------------------------
Another problem is ___________________
process is created and released , the scheduling process is actually _______________________ .
In java how to understand the process? ? Because much of the score , posted in this problem, right ?
------ For reference only -------------------------------------- -
because your Trans () method does not return a value, so
System.out.println (intIndex);
System.out.println (str);
output is 100 ,
because stringBuffer append a 1 , it will be initialized 100 stitching on the back of a string is 1001

没有评论:

发表评论