Skip to content

Instantly share code, notes, and snippets.

@jweinst1
Created September 1, 2015 17:37
Show Gist options
  • Select an option

  • Save jweinst1/16a80f39e1d367ce5148 to your computer and use it in GitHub Desktop.

Select an option

Save jweinst1/16a80f39e1d367ce5148 to your computer and use it in GitHub Desktop.
Swaps two items in an array in Java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(Arrays.toString(swapitem(lst, 3, 1)));
}
static int[] lst = {2, 3, 1, 5, 6, 7};
static int[] swapitem(int[] x, int y, int z) {
int temp = x[y];
x[y] = x[z];
x[z] = temp;
return x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment