Arrays copyOfRange() method in java

// arrays copyOfRange() method in java example
import java.util.Arrays;
public class ArrayCopyOfRangeDemo 
{
   public static void main(String[] args) 
   {
      int[] arrNumber = { 66, 67, 68, 69, 70, 71, 72 };
      System.out.println("Given array: ");
      for(int a = 0; a < arrNumber.length; a++) 
      {
         System.out.println(arrNumber[a]); 
      }
      int[] copyNum = Arrays.copyOfRange(arrNumber, 2, 6);
      System.out.println("----------------------");
      System.out.println("Between range 2 and 6: ");
      for(int a : copyNum)
      {
         System.out.print(a + " ");
      }
      System.out.println();
   }
}

4.14
7
Altexpape 110 points

                                    // arrays copyofrange short data type example
import java.util.Arrays;
public class ArrayCopyShort
{
   public static void main(String[] args)
   {
      short[] arrShort1 = new short[] {14, 23, 41};
      System.out.println(&quot;ARRAY COPY OF RANGE METHOD - SHORT DATA TYPE&quot;);
      System.out.println(&quot;--------------------------------------------&quot;);
      System.out.println(&quot;Given array : &quot;);
      for(int a = 0; a &lt; arrShort1.length; a++)
      {
         System.out.println(arrShort1[a]);
      }
      // java copyofrange
      short[] arrShort2 = Arrays.copyOfRange(arrShort1, 1, 3);
      System.out.println(&quot;Copied array : &quot;);
      for(int a = 0; a &lt; arrShort2.length; a++)
      {
         System.out.println(arrShort2[a]);
      }
   }
}

4.14 (7 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source