Java tutorial
//package com.java2s; import java.util.Map; public class Main { private static final String TOKEN_PREFIX = "T"; private static final String TOKEN_MAIN = TOKEN_PREFIX + "0"; /** * Stick map into one sentence. * * @param postfixMap * @return */ private static String stickFragments(Map<String, String> postfixMap) { for (int index = 1; index < postfixMap.size(); index++) { String value = postfixMap.get(TOKEN_PREFIX + index); if (value == null) { continue; } for (int innerIndex = index + 1; innerIndex < postfixMap.size(); innerIndex++) { String innerValue = postfixMap.get(TOKEN_PREFIX + innerIndex); if (innerValue != null) { innerValue = innerValue.replace(TOKEN_PREFIX + index, value); postfixMap.put(TOKEN_PREFIX + innerIndex, innerValue); } } String innerValue = postfixMap.get(TOKEN_MAIN); innerValue = innerValue.replace(TOKEN_PREFIX + index, value); postfixMap.put(TOKEN_MAIN, innerValue); } return postfixMap.get(TOKEN_MAIN); } }