Interchanging first and second halves of strings | Java code to create two new strings by swapping first and second halves ; Function to concatenate two different halves of given strings ; Creating new strings by exchanging the first half of a and b . Please refer below for details of substring . https : www . geeksforgeeks . org / java - lang - string - substring - java / ; Driver function ; Calling function
import java . io . * ; class ns { public static void swapTwoHalves ( String a , String b ) { int la = a . length ( ) ; int lb = b . length ( ) ; String c = a . substring ( 0 , la / 2 ) + b . substring ( lb / 2 , lb ) ; String d = b . substring ( 0 , lb / 2 ) + a . substring ( la / 2 , la ) ; System . out . println ( c + "NEW_LINE" + d); } public static void main ( String args [ ] ) { String a = " remuneration " ; String b = " day " ; swapTwoHalves ( a , b ) ; } }