Here you can find the source of replaceByMap(String _searchStr, Map
Parameter | Description |
---|---|
_searchStr | search string |
_replacements | replacement |
public static String replaceByMap(String _searchStr, Map<String, String> _replacements)
//package com.java2s; //License from project: Open Source License import java.util.Map; import java.util.Map.Entry; public class Main { /**/*from w w w . j av a 2s . c o m*/ * Replace all placeholders in given string by value of the corresponding key in given Map. * * @param _searchStr search string * @param _replacements replacement * @return String or null if _searchStr was null */ public static String replaceByMap(String _searchStr, Map<String, String> _replacements) { if (_searchStr == null) { return null; } if (_replacements == null || _replacements.isEmpty()) { return _searchStr; } String str = _searchStr; for (Entry<String, String> entry : _replacements.entrySet()) { str = str.replace(entry.getKey(), entry.getValue()); } return str; } /** * Checks if the given String is either null or empty. * Blank means:<br> * <pre> * " " - false * "" - true * null - true * " xx" - false * </pre> * @param _str string to test * @return true if string is empty or null, false otherwise */ public static boolean isEmpty(String _str) { if (_str == null) { return true; } return _str.isEmpty(); } }