Created
June 23, 2021 17:40
-
-
Save jeffscottbrown/f3d4ec6240345dc3bab54ebbd45a759e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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