Here you can find the source of combineIndices(String[] in, String delimiter, int i, int j)
Parameter | Description |
---|---|
in | The individual lines. |
delimiter | What to combine the strings with. |
i | The line to start on (inclusive). |
Parameter | Description |
---|---|
IllegalArgumentException | If i < 0 or j > in.length. |
public static String combineIndices(String[] in, String delimiter, int i, int j) throws IllegalArgumentException
//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(); } }