You can use
JDK > 1.5
Arrays.copyOfRange(Object[] src, int from, int to)
Javadoc
JDK <= 1.5
System.arraycopy(Object[] src, int srcStartIndex, Object[] dest, int dstStartIndex, int lengthOfCopiedIndices);
Javadoc
Answer from Jigar Joshi on Stack Overflow Top answer 1 of 10
419
You can use
JDK > 1.5
Arrays.copyOfRange(Object[] src, int from, int to)
Javadoc
JDK <= 1.5
System.arraycopy(Object[] src, int srcStartIndex, Object[] dest, int dstStartIndex, int lengthOfCopiedIndices);
Javadoc
2 of 10
147
Arrays.copyOfRange(..) was added in Java 1.6. So perhaps you don't have the latest version. If it's not possible to upgrade, look at System.arraycopy(..)
08:26
Print All Subarrays of a Given Array - Non-Recursive Solution | ...
09:37
Generate All Subarrays of an Array Using Recursion | Medium - YouTube
14:44
Arrays Series #4- Find subarray with given sum - Solution Explained ...
Leetcode 2799. | Count Complete Subarrays in an Array
27:49
Solve Subarray Problems Quickly With Sliding Window Technique | ...
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Arrays.html
Arrays (Java Platform SE 8 )
July 21, 2026 - The sorting algorithm is a parallel sort-merge that breaks the array into sub-arrays that are themselves sorted and then merged. When the sub-array length reaches a minimum granularity, the sub-array is sorted using the appropriate Arrays.sort method. If the length of the specified array is less than the minimum granularity, then it is sorted using the appropriate Arrays.sort method.
W3Schools
w3schools.com › java › java_arrays.asp
Java Arrays
Java Wrapper Classes Java Generics Java Annotations Java RegEx Java Threads Java Lambda Java Advanced Sorting ... How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowels Count Digits in a String Reverse a String Palindrome Check Check Anagram Convert String to Array Remove Whitespace Count Character Frequency Sum of Array Elements Find Array Average Sort an Array Find Smallest Element Find Largest Element Second Largest Array Min and Max Array Merge Two Arrays Remove Duplicates Find Duplicates Shuffle an Array Factorial of a Number Fibonacci Sequence Find GCD Check Prime Number ArrayList Loop HashMap Loop Loop Through an Enum
CodeSignal
codesignal.com › learn › courses › mastering-complex-data-structures-in-java › lessons › understanding-and-using-arrays-in-java
Understanding and Using Arrays in Java
Java · class ArrayExample { public Object[] createNestedArray() { return new Object[] {"apple", new Object[] {"banana", "cherry"}}; } } public class Solution { public static void main(String[] args) { ArrayExample arrayExample = new ArrayExample(); Object[] nestedArray = arrayExample.createNestedArray(); System.out.println(nestedArray[0]); // Output: apple Object[] subArray = (Object[]) nestedArray[1]; System.out.println(subArray[0]); // Output: banana System.out.println(subArray[1]); // Output: cherry } } Java ·
Pressbooks
pressbooks.lib.jmu.edu › programmingpatterns › chapter › subarrays
Subarrays – Patterns for Beginning Programmers
May 6, 2022 - One of Java’s most convenient features is the length attribute associated with each array. Because of this feature, it isn’t necessary to pass both the array and its length to a method (as it is in some other languages). However, it leads to people creating methods with inflexible signatures. The subarray ...
Educative
educative.io › answers › what-is-arrayutilssubarray-in-java
What is ArrayUtils.subarray in Java?
The array [1,2,3,4,5] is a result of applying the subarray function, because the end index value would get changed to the array length.
Utkarsh1504
utkarsh1504.github.io › DSA-Java › subarrays
Subarrays – Arrays – Data Structures & Algorithms
class solution { // Recursive function to print all possible subarrays // for given array static void printSubArrays(int []arr, int start, int end) { // Stop if we have reached the end of the array if (end == arr.length) return; // Increment the end point and start from 0 else if (start > end) printSubArrays(arr, 0, end + 1); // Print the subarray and increment the starting point else { System.out.print("["); for (int i = start; i < end; i++){ System.out.print(arr[i]+", "); } System.out.println(arr[end]+"]"); printSubArrays(arr, start + 1, end); } return; } public static void main(String args[]) { int []arr = {1, 2, 3}; printSubArrays(arr, 0, 0); } }
OneCompiler
onecompiler.com › qna › 3xmsrgvcw › -java-ho-to-get-a-sub-array-from-an-array-with-start-index-and-end-index
[Java] Ho to get a sub array from an array with start index and end index? - Q&A - OneCompiler
import java.util.Arrays; public class JavaArrays { public static void main(String[] args) { int[] numbers = { 45, 22, 67, 90, 47, 88 }; int fromIndex = 1; int toIndex = 3; int[] subArray = Arrays.copyOfRange(numbers, fromIndex, toIndex); System.out.println("Subarray is: " + Arrays.toString(subArray)); } } Subarray is: [22, 67] Try online here: https://onecompiler.com/java/3xmswryc9 ·
GeeksforGeeks
geeksforgeeks.org › dsa › generating-subarrays-using-recursion
Generating All Subarrays - GeeksforGeeks
February 7, 2025 - #include <stdio.h> //Prints all subarrays in arr[0..n-1] void subArray(int arr[], int n) { // Pick starting point for (int i = 0; i < n; i++) { // Pick ending point for (int j = i; j < n; j++) { // Print subarray between current starting and ending points for (int k = i; k <= j; k++) { printf("%d ", arr[k]); } printf("\n"); } } } int main() { int arr[] = {1, 2, 3, 4}; int n = sizeof(arr) / sizeof(arr[0]); printf("All Non-empty Subarrays:\n"); subArray(arr, n); return 0; } ... import java.util.ArrayList; public class GfG { //Prints all subarrays in arr[0..n-1] static void subArray(ArrayList<Int
TutorialsPoint
tutorialspoint.com › find-all-the-subarrays-of-a-given-array-in-java
Find All the Subarrays of a Given Array in Java
In this approach, we find all the subarrays but using recursion. import java.io.*; public class Main { //main method public static void main(String[] args) { // The array elements int arr[] = { 10, 2, 3}; System.out.println("The subarrays are-"); // Calling the recursive function printSubArrays(arr, 0, 0); } // Recursive FUnction to Find all the subarrays static void printSubArrays(int[] arr, int head, int tail) { // Exits the function if we have reached the end if (tail == arr.length) return; // Increases the first index and calls itself else if (head > tail) printSubArrays(arr, 0, tail + 1); // Print the subarray and then increases the first element index else { for (int i = head; i < tail; i++) System.out.print(arr[i] + " "); System.out.println(arr[tail]); printSubArrays(arr, head + 1, tail); } return; } }
Reddit
reddit.com › r/javahelp › confused between subarray vs substring vs subsequence vs subset - where to start?
Confused between Subarray vs Substring vs Subsequence vs Subset - where to start? : r/javahelp
April 18, 2025 - A subarray is a part of an array, a substring is a part of a string etc. They are all the very same thing, but for different data structures. Do you actually want to know when and where to use an arrays vs.
YouTube
youtube.com › watch
Find Sub Array Of An Array | FREE DSA Course in JAVA | Lecture 68 - YouTube
We have to write a program to print all the sub arrays of an array in java.Consider this with example 1,2,3,4,5 is an array.All sub arrays of this array will...
Published: February 5, 2023
ClojureVerse
clojureverse.org › questions & help › how to?
Subvec of Java Arrays - How to? - ClojureVerse
March 25, 2019 - Is there anything similar to subvec for Java Arrays? Crrently I’m using take and nthnext (Update: This is just an example on how I’m using take and nthnext): (defn sub-seq [from to coll] ;; Update: Name was subseq before, but core already has that name. (let [size (- to from)] (take size (nthnext coll from)))) But I feel there should be an already core function for this or something.