Java examples for java.lang:String Format
Formats the string with replacement values
/**//from w ww.j av a2 s . c o m * Copyright (c) 2005-2006 Aptana, Inc. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html. If redistributing this code, * this entire header must remain intact. */ //package com.java2s; import java.text.MessageFormat; public class Main { /** * Formats the string with replacement values * * @param str * @param replacement * @return String */ public static String format(String str, long replacement) { return MessageFormat.format(str, new Object[] { new Long( replacement) }); } /** * Formats the string with replacement values * * @param str * @param replacement * @return String */ public static String format(String str, int replacement) { return MessageFormat.format(str, new Object[] { new Integer( replacement) }); } /** * Formats the string with replacement values * * @param str * @param replacement * @return String */ public static String format(String str, String replacement) { return MessageFormat.format(str, new Object[] { replacement }); } /** * Formats the string with replacement values * * @param str * @param replacement * @return String */ public static String format(String str, Object replacement) { return MessageFormat.format(str, new Object[] { replacement.toString() }); } /** * Formats the string with replacement values * * @param str * @param replacements * @return String */ public static String format(String str, Object[] replacements) { return MessageFormat.format(str, replacements); } }