Java Array Copy copyArrayWhenNotNull(byte[] source)

Here you can find the source of copyArrayWhenNotNull(byte[] source)

Description

Copies array or returns null when source is null.

License

Apache License

Parameter

Parameter Description
source a parameter

Return

copied array

Declaration

final public static byte[] copyArrayWhenNotNull(byte[] source) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;

public class Main {
    /**//from   w  w  w  .  ja  va 2 s .c  o  m
     * Copies array or returns null when source is null.
     * @param source
     * @return copied array
     */
    final public static byte[] copyArrayWhenNotNull(byte[] source) {
        if (source != null) {
            return Arrays.copyOf(source, source.length);
        } else {
            return null;
        }
    }
}

Related

  1. copyArrayMax(int[] local, int[] merged)
  2. copyArrayRange(final byte[] value, int start, int end)
  3. copyArrays(byte[] dest, byte[] source, int fromIdx)
  4. copyArrays(byte[] src, int srcOffset, byte[] dst, int dstOffset, int numBytes)
  5. copyArrayToStr(String[] src, String del)
  6. copyBytes(byte[] data, int from, int to)
  7. copyExcept(E[] orig, E excludedElem)
  8. copyIfExceeded(int[] arr, int len)
  9. copyIntoBigger(int[] array, int newSize, int defaultValue)