copying portion of object array in Java -


If I have an object array in Java then car [] a = {0,2,2,3 , 4, 5, 6, 7}. How do I copy this array from 2 to 7?

I thought about making it for a loop

  car [b] = new car [a.length - 2]; For (inti = 2; i & lt; a.length; i ++) {b [i - 2] = a [i]; }   

Is there another way to use Java built in some library? If so, will it be more or less efficient than the proposed loop?

You can use the copyOfRange to copy some of the categories arrays class

sample:

  Arrays.copyOfRange (b, 2, 7);   

method

  copyOfRange (T [] from the original, int, int)    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -