Java String Remove removeAndConcatenateAlternate(String s1, String s2)

Here you can find the source of removeAndConcatenateAlternate(String s1, String s2)

Description

remove And Concatenate Alternate

License

Open Source License

Parameter

Parameter Description
s1 a parameter
s2 a parameter

Declaration

public static String removeAndConcatenateAlternate(String s1, String s2) 

Method Source Code

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

import java.util.*;

public class Main {
    /**//from w ww .j ava2s .c  om
     *
     * @param s1
     * @param s2
     * @return
     */
    public static String removeAndConcatenateAlternate(String s1, String s2) {
        String s3 = s1.concat(s2);
        Map<Character, List<Integer>> tracker = new HashMap<>();
        for (int i = 0; i < s3.length(); i++) {
            char c = s3.charAt(i);
            if (tracker.containsKey(c)) {
                tracker.get(c).add(i);
            } else {
                List<Integer> indexes = new ArrayList<>();
                indexes.add(i);
                tracker.put(c, indexes);
            }
        }
        StringBuilder builder = new StringBuilder();
        Iterator<Map.Entry<Character, List<Integer>>> iterator = tracker
                .entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Character, List<Integer>> entry = iterator.next();
            if (entry.getValue().size() == 1) {
                builder.append(entry.getKey());
            }
        }
        return builder.toString();
    }
}

Related

  1. getAndRemove(String key)
  2. parseAndRemoveDuplicates(String s, String del)
  3. removeAll(String origStr, String removeStr)
  4. removeAll(String targetStr, String removeStr)
  5. removeBlankLines(String s)
  6. removeCommandFromString(String commandString)
  7. removeEmpties(final String... values)
  8. removeEscape(String s_)