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
Here you go. Try this:
String a = "one"; String b = "two"; //String temp=null; int i = a.length(); a += b; b = a.substring(0, i); a = a.substring(i, a.length()); System.out.println(a + " " + b);
Take any value in as string in a variable. It will be swap.