Here you can find the source of mergeStringLines(String lineOne, String lineTwo, int keyIndex, int insertingIndex)
static public String mergeStringLines(String lineOne, String lineTwo, int keyIndex, int insertingIndex)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Arrays; public class Main { static public String mergeStringLines(String lineOne, String lineTwo, int keyIndex, int insertingIndex) { String mergedLine = ""; String[] splittingLine = lineOne.split(","); String lineTwoWOKey = removeColumn(lineTwo, keyIndex); if (splittingLine.length <= insertingIndex) mergedLine = lineOne + "," + lineTwoWOKey; else {/*from w w w.j a v a 2 s . co m*/ mergedLine = getMergedLine(lineOne, lineTwoWOKey, insertingIndex); } return mergedLine; } static String removeColumn(String line, int index) { ArrayList<String> splittingLine = new ArrayList<String>( Arrays.asList(line.split(","))); splittingLine.remove(index); return strArrayListToString(splittingLine); } static void removeColumn(ArrayList<String> lines, int index) { for (int i = 0; i < lines.size(); i++) { lines.set(i, removeColumn(lines.get(i), index)); } } static String getMergedLine(String lineOne, String lineTwo, int insertingIndex) { ArrayList<String> lstLineOne = new ArrayList<String>( Arrays.asList(lineOne.split(","))); ArrayList<String> lstLineTwo = new ArrayList<String>( Arrays.asList(lineTwo.split(","))); for (int i = 0; i < lstLineTwo.size(); i++) { lstLineOne.add(insertingIndex + i, lstLineTwo.get(i)); } return strArrayListToString(lstLineOne); } static String strArrayListToString(ArrayList<String> lstLine) { String line = ""; for (int i = 0; i < lstLine.size(); i++) { line = line + lstLine.get(i); if (i != lstLine.size() - 1) line = line + ","; } return line; } }