Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java Copying Arrays Using copyOfRange() method

// To use toString() and copyOfRange() method
import java.util.Arrays;

class ArraysCopy {
    public static void main(String[] args) {
      
        int[] source = {2, 3, 12, 4, 12, -2};
      
        // copying entire source array to destination
        int[] destination1 = Arrays.copyOfRange(source, 0, source.length);      
        System.out.println("destination1 = " + Arrays.toString(destination1)); 
      
        // copying from index 2 to 5 (5 is not included) 
        int[] destination2 = Arrays.copyOfRange(source, 2, 5); 
        System.out.println("destination2 = " + Arrays.toString(destination2));   
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java how to override a private method 
Java :: sort array java 
Java :: simple java program 
Java :: java.lang.ExceptionInInitializerError: null 
Java :: reverse sentence in java 
Java :: sort string java 
Java :: how to check if a char is a letter java 
Java :: sprint jpa properties for application.yml 
Java :: create file from byte array java 
Java :: password encryption and decryption in java 
Java :: string replace last character java 
Java :: get first character of string java 
Java :: public static void main(string args) 
Java :: change color of action bar android studio 
Java :: What is null mean in java 
Java :: clear array java 
Java :: replace all punctuation in string java 
Java :: object to double java 
Java :: java game 
Java :: java array declaration 
Java :: java logger error 
Java :: android splash screen 
Java :: java map not null 
Java :: sorting the characters in a String in java 
Java :: foreach java 
Java :: arraylist java 
Java :: flutter remove last caracter from string 
Java :: java parse unix timestamp 
Java :: association in java 
Java :: map interation in java 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =