Swap two strings in Java, by passing them to a utility function, but without returning objects or using wrapper classes

前端 未结 9 2239
既然无缘
既然无缘 2020-12-16 20:31

I am trying to swap two strings in Java. I never really understood \"strings are immutable\". I understand it in theory, but I never came across it in practice.

Also

9条回答
  •  借酒劲吻你
    2020-12-16 21:01

    String s1 = "Hello";
    String s2 = "World";
        s1=s1+" "+s2;
    s2=s1.split(" ")[0];
    s1=s1.split(" ")[1];
    System.out.println(s1 + " " + s2);
    

提交回复
热议问题