Java Utililty Methods List Merge

List of utility methods to do List Merge

Description

The list of methods to do List Merge are organized into topic(s).

Method

StringdoMerge(List list, String sep)
do Merge
StringBuilder builder = new StringBuilder();
for (String s : list) {
    builder.append(s);
    builder.append(sep);
return builder.toString();
StringgetMergedLines(List strings)
get Merged Lines
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < strings.size(); i++) {
    sb.append(strings.get(i));
    if (i < strings.size() - 1) {
        sb.append("\\n");
return sb.toString();
...
ListgetMergedSpeakerList()
get Merged Speaker List
return null;
ListgetMergeindexes(List spans, List indexes)
get Mergeindexes
List<Integer> mindexes = new ArrayList<Integer>();
for (int i = 0; i < spans.size() - 1; i++) {
    String s = spans.get(i);
    if (s.length() + indexes.get(i) == indexes.get(i + 1)) {
        mindexes.add(indexes.get(i + 1));
return mindexes;
...
voidmapMergeAdd(Map> map, Map> mapToAdd)
map Merge Add
for (Map.Entry<T, List<U>> e : mapToAdd.entrySet()) {
    if (!map.containsKey(e.getKey())) {
        map.put(e.getKey(), new ArrayList<U>());
    map.get(e.getKey()).addAll(e.getValue());
Listmerge(final List> listOfLists)
merge
List<T> mergedElements = listOfLists.get(0);
for (int i = 1; i < listOfLists.size(); i++) {
    Collection<? extends T> elements = listOfLists.get(i);
    mergedElements.addAll(elements);
return mergedElements;
Stringmerge(final List list, final String seperator)
Merge all strings into a single string with the delimiter in between the items Can be seen as the reverse of a string splitter
if (list == null)
    return "";
StringBuilder sb = new StringBuilder();
for (String item : list) {
    if (item.length() == 0)
        continue;
    if (sb.length() > 0)
        sb.append(seperator); 
...
Listmerge(final List a, final List b)
merge
final List<T> retVal = new ArrayList<T>();
retVal.addAll(a);
retVal.addAll(b);
return retVal;
Listmerge(final List aList, final List bList)
merge
if (aList == null && bList == null) {
    return Collections.emptyList();
if (aList != null && bList == null) {
    return Collections.unmodifiableList(aList);
if (aList == null && bList != null) {
    return Collections.unmodifiableList(bList);
...
String[]merge(final String[] input, final String[] list)
Merge to string arrays
final List<String> v = new ArrayList<String>(Arrays.asList(list));
for (final String anInput : input) {
    if ((null != anInput) && !v.contains(anInput)) {
        v.add(anInput);
return v.toArray(new String[v.size()]);