Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeffscottbrown/f3d4ec6240345dc3bab54ebbd45a759e to your computer and use it in GitHub Desktop.
Save jeffscottbrown/f3d4ec6240345dc3bab54ebbd45a759e to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class JavaDemo {
public static void main(String[] args) {
int[]array = {1,2,3,4,5,6,7};
int[] newArray = reorderFromIndex(array, 4);
for(int i = 0; i < newArray.length; i++ ) {
System.out.println(newArray[i]);
}
}
static int[] reorderFromIndex(int[] array, int index) {
List info = Arrays.stream(array).boxed().collect(Collectors.toList());
List<Integer> newList = info.subList(index, array.length);
newList.addAll(info.subList(0, index-1));
return newList.stream().mapToInt(Integer::intValue).toArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment