How to swap two string variables in Java without using a third variable

后端 未结 18 804
梦谈多话
梦谈多话 2021-02-02 12:30

How do I swap two string variables in Java without using a third variable, i.e. the temp variable?

String a = \"one\"
String b = \"two\"
String temp = null;
temp         


        
18条回答
  •  长情又很酷
    2021-02-02 13:21

    • Actually, the code in your question did not swap String a,b.

      You should see this issue: Swap two strings in Java, by passing them to a utility function, but without returning objects or using wrapper classes

    • And Java is passing by value: Is Java "pass-by-reference" or "pass-by-value"?

提交回复
热议问题