Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java string swap two characters

String originalString = "abcde";
//Strings are immutable
char[] c = originalString.toCharArray(); 
//Swap
char temp = c[0];
c[0] = c[1];
c[1] = temp;
//Result
String swappedString = new String(c);
 
PREVIOUS NEXT
Tagged: #java #string #swap #characters
ADD COMMENT
Topic
Name
3+4 =