Here you can find the source of nextPermutation(int[] is)
public static boolean nextPermutation(int[] is)
//package com.java2s; //License from project: Open Source License public class Main { public static boolean nextPermutation(int[] is) { int n = is.length; for (int i = n - 1; i > 0; i--) { if (is[i - 1] < is[i]) { int j = n; while (is[i - 1] >= is[--j]) ;// w ww. j a v a2 s .c om swap(is, i - 1, j); rev(is, i, n); return true; } } rev(is, 0, n); return false; } public static void swap(int[] is, int i, int j) { int t = is[i]; is[i] = is[j]; is[j] = t; } public static void rev(int[] is, int s, int t) { while (s < --t) swap(is, s++, t); } }