- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the method copyOfRange(int[] original, int from, int to) do in java?
The copyOfRange(int[] original, int from, int to) method of java.util.Arrays class copies the specified range of the specified array into a new array. The final index of the range (to), which must be greater than or equal to from, may be greater than original. Length, in which case 0 is placed in all elements of the copy whose index is greater than or equal to original. Length - from. The length of the returned array will be to - from.
Example
import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { int[] arr1 = new int[] {5, 62, 15}; System.out.println("Printing 1st array:"); for (int i = 0; i < arr1.length; i++) { System.out.println(arr1[i]); } int[] arr2 = Arrays.copyOfRange(arr1, 2, 6); System.out.println("Printing new array:"); for (int i = 0; i < arr2.length; i++) { System.out.println(arr2[i]); } } }
Output
Printing 1st array: 5 62 15 Printing new array: 15 0 0 0
- Related Articles
- What does the method copyOf(int[] original, int newLength) do in java?
- What does the method fill(int[], int fromIndex, int toIndex, int val) do in java?
- What does the method sort(int[] a, int fromIndex, int toIndex) do in java?
- What does the method fill(int[], int val) do in java?
- What does the method fill(obj[], int fromIndex, int toIndex, int val) do in java?
- What does the method equals(int[] a1, int[] a2) do in java?
- What does the method removeRange(int fromIndex, int toIndex) do in java?
- What does the method sort(obj[] a, int fromIndex, int toIndex) do in java?
- What does the method remove(int) do in java?
- What does the method int capacity() do in java?
- What does the method get(int) do in java?
- What does the method hashCode(int[] a) do in java?
- What does the method sort(int[] a) do in java?
- What does the method elementAt(int index) do in java?
- What does the method removeElementAt(int index) do in java?

Advertisements