/**
* @author lautturi.com
* Java example: java string how to swap two characters
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
String originalString = "hella jova";
//Strings are immutable
char[] c = originalString.toCharArray();
char temp = c[7];
c[7] = c[4];
c[4] = temp;
//Result
String newStr = new String(c);
System.out.println(newStr);
}
}
output:
hello java