Java Array Combine combineIndices(String[] in, String delimiter, int i, int j)

Here you can find the source of combineIndices(String[] in, String delimiter, int i, int j)

Description

Combine indices into one string.

License

Open Source License

Parameter

Parameter Description
in The individual lines.
delimiter What to combine the strings with.
i The line to start on (inclusive).

Exception

Parameter Description
IllegalArgumentException If i < 0 or j > in.length.

Return

The lines combined together with the delimiter.

Declaration

public static String combineIndices(String[] in, String delimiter, int i, int j)
        throws IllegalArgumentException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   www . ja  v a  2s  . co  m*/
     * Combine indices into one string.
     *
     * @param in
     *          The individual lines.
     * @param delimiter
     *          What to combine the strings with.
     * @param i
     *          The line to start on (inclusive).
     *
     * @return The lines combined together with the delimiter.
     *
     * @throws IllegalArgumentException
     *          If i < 0 or j > in.length.
     */
    public static String combineIndices(String[] in, String delimiter, int i, int j)
            throws IllegalArgumentException {
        if (i < 0 || j > in.length) {
            throw new IllegalArgumentException("indices out of bounds!");
        }

        if (in.length == 0 || i == j) {
            return "";
        }

        StringBuilder sb = new StringBuilder();

        for (; i < j; i++) {
            sb.append(in[i]).append(delimiter);
        }

        sb.deleteCharAt(sb.length() - 1); // remove the last newline character

        return sb.toString();
    }
}

Related

  1. combineArrays(float[]... arrays)
  2. combineByteArray(byte[] one, byte[] two)
  3. combineChannels(int[][] a, int[][] r, int[][] g, int[][] b, int[][] pixels)
  4. combineChunksToByteArray(byte chunks[][])
  5. combineComponent(float[] partsComponent, float[] partsAlpha, int partsN)
  6. combineIntArrays(int[] A, int[] B)
  7. combineLines(String[] lines)