Here you can find the source of removeAndConcatenateAlternate(String s1, String s2)
Parameter | Description |
---|---|
s1 | a parameter |
s2 | a parameter |
public static String removeAndConcatenateAlternate(String s1, String s2)
//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(); } }