Java implementation of the approach
class GFG { static String swap ( String str , int i , int j ) { StringBuilder sb = new StringBuilder ( str ) ; sb . setCharAt ( i , str . charAt ( j ) ) ; sb . setCharAt ( j , str . charAt ( i ) ) ; return sb . toString ( ) ; }