Pass reference value

Source: Internet
Author: User
Code:
  1. Code:
  2. 1.
  3. 2. Import java. util. arraylist;
  4. 3. Import java. util. iterator;
  5. 4. Import java. util. List;
  6. 5. // pass the reference value
  7. 6. Public class person {
  8. 7.
  9. 8. Public void changeobject (student s ){
  10. 9. S. setname ("careers111 ");
  11. 10 .}
  12. 11.
  13. 12. Public void changstring (string Str ){
  14. 13. Str = STR + "world ";
  15. 14 .}
  16. 15.
  17. 16. Public void changearray (string [] array ){
  18. 17./* string [] STR = {"ie", "Firefox", "theworld", "Chrome", "safari", "Opera "};
  19. 18. array = STR;
  20. 19 .*/
  21. 20. array [0] = "change ";
  22. 21 .}
  23. 22.
  24. 23. Public static void main (string [] ARGs ){
  25. 24.
  26. 25. // object
  27. 26. Person P = new person ();
  28. 27. Student s = new student ();
  29. 28. S. setname ("careers000 ");
  30. 29. P. changeobject (s );
  31. 30. system. Out. println ("S. getname () =" + S. getname (); // S. getname () = careers111
  32. 31.
  33. 32. // string
  34. 33. String STR = "hello ";
  35. 34. P. changstring (STR );
  36. 35. system. Out. println ("str =" + Str); // STR = Hello
  37. 36.
  38. 37. // Array
  39. 38. string [] array = {"oracle", "DB2", "Informix", "MySQL", "hsql", "access", "sqlserver", "sybase "};
  40. 39. P. changearray (array );
  41. 40. system. Out. println ("array [0] =" + array [0]); //
  42. 41.
  43. 42. // list
  44. 43. List <string> List = new arraylist <string> ();
  45. 44. List. Add ("111 ");
  46. 45. List. Add ("222 ");
  47. 46. List. Add ("333 ");
  48. 47. iterator <string> it = List. iterator ();
  49. 48. While (it. hasnext ()){
  50. 49. If (it. Next () = "222 "){
  51. 50. It. Remove ();
  52. 51 .}
  53. 52 .}
  54. 53. system. Out. println (list. Size (); // 2
  55. 54 .}
  56. 55 .}
  57. 56. class student {
  58. 57. Private string name;
  59. 58. Public String getname (){
  60. 59. Return name;
  61. 60 .}
  62. 61. Public void setname (string name ){
  63. 62. This. Name = Name;
  64. 63 .}
  65. 64 .}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.