How to swap two strings without using the third variable ?

How to swap two strings without using the third variable ?

Program
Before swapping....
The first String = one
The second String = two

After swapping....
The first String = two
The second String = one

public class Main
{
	public static void main(String[] args) 
	{
		
        String s1 = "One"; 
        String s2 = "Two"; 
          
        // Print String before swapping 
        System.out.println("Strings before swap: s1 = " +s1 + " and s2 = "+s2); 
          
        // append 2nd string to 1st 
        s1 = s1 + s2; 
          
        // store initial string a in string b 
        s2 = s1.substring(0,s1.length()-s2.length()); 
          
        // store initial string b in string a 
        s1 = s1.substring(s2.length()); 
          
        // print String after swapping 
        System.out.println("Strings after swap: s1 = " +   s1 + " and s2 = " + s2);   
	}

}

Output:

Strings before swap: s1 = One and s2 = Two
Strings after swap: s1 = Two and s2 = One





More Questions


19 . How to count the number of words in a given string sentence?
20 . How to reverse the words from the given string sentence?
21 . How to swap two strings without using the third variable?