How to swap two String values without using a
third variable?

Answer Posted / shyambaishya

Using Java:
===========
String s1 = "Shyam Sundar Baishya" ;
String s2 ="Dilip Kumar";
System.out.println("Before swapping ............");
System.out.println("s3 == "+s1);
System.out.println("s4 == "+s2);
s1= s1+s2;
System.out.println("....................");
System.out.println("After swapping ............");
s2 = s1.substring(0,(s1.length()-s2.length()));
s1 = s1.substring(s2.length(),(s1.length()));
System.out.println("s3 == "+ s1);
System.out.println("s4 == "+ s2);

Is This Answer Correct ?    49 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

in IT trend mantis meant what? how to know mantis in IT trends? detail description about mantis?

1645


how does database connection using ADO.NET?

1521


Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 1 number. Find the missing number

727


Which method protects back button to retrieve old value from previous page in Struts.

1449


WS-NUM PIC S9(05)V(02) SIGN TRAILING SEPARATE MOVE '0050000+' TO WS-NUM The value stored is 00500,00+ MOVE '0050000-' TO WS-NUM Then what is the value will be stored in WS-NUM? Am getting '-00500,00'.....>>> What should I declare to WS-NUM so that I can get correct values for both + & - signs.

1848






Code for display the images from drive using vb 6.0?

4288


What is the use of sas software? Is sas and sap are different?

1014


what is meaning of MDM in sap?let me know that meaning

1680


can we allocate memory for interface? if no then why?

1468


what are the advantages of sap on other software ?

1730


10.Define filters,binary to hexadecimal,hexadecimal to decimal?

1514


Which CRM is better to opt, Sebiel CRM or Salesforce CRM or sap CRM? which institute is best one in hyderabad

1845


What is the difference between CLEAR & RESET and OPEN & CLOSE OPCOEDS(USING RPG/400).wheare we can use this?can any body tell me in real time senario with example please?

1567


how will you code the subfile which is in editing mode (multiple case subfile)?

1598


how to add Servlet-api.jar file into eclipse 3.3.2 ?

4052