[Java] Copy array to array (without loop)

  1. arraycopy () specifies the copy length and starting position
    System.arraycopy (dataType [] srcArray, int srcIndex, int destArray, int destIndex, int length) The
    target array must exist

  2. clone ()
    array_name.clone () The
    return value is object, so it is necessary to perform type conversion

  3. copyOf () specifies the length
    Arrays.copyOf (dataType [] srcArray, int length); the
    default starts from 0, and length is the length of the new array

  4. copyOfRange specifies the starting and ending points
    Arrays.copyOfRange (dataType [] srcArray, int startIndex, int endIndex)

Except that the first one is a replacement, the rest is reconstructed if the target array exists

Refer

Published 70 original articles · Likes0 · Visits 1705

Guess you like

Origin blog.csdn.net/weixin_44807751/article/details/103812339