0
Can anyone suggest other things also
Swap String without using third variable https://code.sololearn.com/cTWjQWnaIRUK/?ref=app
1 ответ
+ 3
I couldn't think of a simpler way to do it than you have.
I base 64-encoded the 2 strings and used a : to separate the encodings. : is not possible in a base 64 encoding so it is a safe delimiter.
import java.util.*;
public class Program
{
public static void main(String[] args) {
String a="hello";
String b="world";
a=Base64.getEncoder().encodeToString(a.getBytes()) + ":" + Base64.getEncoder().encodeToString(b.getBytes());
b = new String(Base64.getDecoder().decode(a.substring(0, a.indexOf(":"))));
a = new String(Base64.getDecoder().decode(a.substring(a.indexOf(":") + 1)));
System.out.println(a);
System.out.println(b);
}
}