Java String Format format(String source, String placeholder, Object... objs)

Here you can find the source of format(String source, String placeholder, Object... objs)

Description

format

License

Open Source License

Declaration

public static String format(String source, String placeholder, Object... objs) 

Method Source Code

//package com.java2s;

import java.util.Iterator;

import java.util.Map;

public class Main {

    public static String format(String source, String placeholder, Object... objs) {
        for (int idx = 0; idx < objs.length; idx++) {
            if (source.contains(placeholder + idx) && objs[idx] != null) {
                source = source.replace(placeholder + idx, objs[idx].toString());
            }//from  ww  w  .  jav a 2s.c o m
        }
        return source;
    }

    public static String format(String source, String placeholder, Map<String, String> formats) {
        Iterator<String> it = formats.keySet().iterator();
        while (it.hasNext()) {
            String format = it.next();
            if (source.contains(placeholder + format) && formats.get(format) != null) {
                source = source.replace(placeholder + format, formats.get(format));
            }
        }
        return source;
    }
}

Related

  1. format(final String s, final int width, final int intend)
  2. format(String longMessage, int charPerLine, int paddingLeft, boolean padFirstLine)
  3. format(String name, char separator)
  4. format(String name, char separator, String prefix, boolean includePrefix, boolean includeLeadingSeparator)
  5. format(String s)
  6. format(String string)
  7. formatCommand(String cmd)
  8. formatDescriptors(String descriptorString)
  9. formatError(String errorMsg)