提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从偏移索引将数组联接到字符串
//来 自 n o w j a v a . c o m //package com.nowjava; import java.util.Collection; public class Main { public static void main(String[] argv) { String[] array = new String[] { "1", "abc", "level", null, "nowjava.com", "asdf 123" }; String joint = "nowjava.com"; System.out.println(join(array, joint)); } public static String join(String[] array, int startIndex, String joint) { String result = ""; for (int i = startIndex; i < array.length; i++) { result += array[i]; if (i < array.length - 1) { result += joint;/** from NowJava.com**/ } } return result; } public static String join(String[] array, String joint) { return join(array, 0, joint); } public static String join(Collection<?> collection, String joint) { String result = ""; int i = 0;