Answers for "java swap op string"

2

swap function java

public static void swap(int[] a, int i, int j){
	int temp = a[i];
  	a[i] = a[j];
  	a[j] = temp;
}
Posted by: Guest on March-16-2021
-1

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);
Posted by: Guest on January-09-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language