Reputation: 7728
Is there a native method in Java to do character swapping inside Strings
. I mean, I need to write a function like this everytime and its pretty boring:
public static String modifyString(String str,int x,int y){
char arr[]=str.toCharArray();
char t= arr[x];
arr[x]=arr[y];
arr[y]=t;
String s= new String(arr);
return s;
}
Upvotes: 0
Views: 432