Ropes Data Structure ( Fast String Concatenation ) | Java program to concatenate two strings ; Function that concatenates strings a [ 0. . n1 - 1 ] and b [ 0. . n2 - 1 ] and stores the result in c [ ] ; Copy characters of A [ ] to C [ ] ; Copy characters of B [ ] ; Driver code ; Concatenate a [ ] and b [ ] and store result in c [ ]
class GFG { static void concatenate ( char a [ ] , char b [ ] , char c [ ] , int n1 , int n2 ) { int i ; for ( i = 0 ; i < n1 ; i ++ ) { c [ i ] = a [ i ] ; } for ( int j = 0 ; j < n2 ; j ++ ) { c [ i ++ ] = b [ j ] ; } } public static void main ( String [ ] args ) { char a [ ] = " Hi ▁ This ▁ is ▁ geeksforgeeks . ▁ " . toCharArray ( ) ; int n1 = a . length ; char b [ ] = " You ▁ are ▁ welcome ▁ here . " . toCharArray ( ) ; int n2 = b . length ; char c [ ] = new char [ n1 + n2 ] ; concatenate ( a , b , c , n1 , n2 ) ; for ( int i = 0 ; i < n1 + n2 - 1 ; i ++ ) { System . out . print ( c [ i ] ) ; } } }