Java Array Sub Array subArray(final char[] source, int from, int to)

Here you can find the source of subArray(final char[] source, int from, int to)

Description

Best for arrays less than 20 cells

License

Apache License

Parameter

Parameter Description
source a parameter
from inclusive
to inclusive

Declaration

public static char[] subArray(final char[] source, int from, int to) 

Method Source Code

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

public class Main {
    /**//  ww w  .j  ava 2s  .  c  o m
     * Best for arrays less than 20 cells
     * @param source
     * @param from inclusive
     * @param to inclusive
     * @return
     */
    public static char[] subArray(final char[] source, int from, int to) {
        char[] target = new char[to - from + 1];
        for (int i = 0; i < target.length; i++) {
            target[i] = source[from + i];
        }
        return target;
    }

    /**
     * Best for arrays less than 20 cells.
     * @param source
     * @param length
     * @return sub-array from 0 of desire length
     */
    public static char[] subArray(final char[] source, int length) {
        return subArray(source, 0, length - 1);
    }
}

Related

  1. subarray(double[] orig, int off, int len)
  2. subarray(double[] orig, int off, int len)
  3. subArray(E[] array, int start)
  4. subArray(final byte[] source, final int start, final int length)
  5. subArray(final byte[] src, final int srcPos, final int length)
  6. subArray(final int[] input, final int start, final int end)
  7. subArray(final long[] array, final int start, final int end)
  8. subarray(final long[] array, int startIndexInclusive, int endIndexExclusive)
  9. subarray(final String[] arr, int first, final int last)