Here you can find the source of getPropertiesString(Properties myProps)
public static String getPropertiesString(Properties myProps)
//package com.java2s; /*// w w w . j av a2s . c o m * Copyright 2009 the original author or authors. * Copyright 2009 SorcerSoft.org. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Enumeration; import java.util.Formatter; import java.util.Properties; public class Main { public static String getPropertiesString(Properties myProps) { int maxKeySize = 0; int maxValueSize = 0; Enumeration<Object> keys = myProps.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = myProps.getProperty(key); if (key.length() > maxKeySize) maxKeySize = key.length(); if (value.length() > maxValueSize) maxValueSize = value.length(); } StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb); // String format = "%" + maxKeySize + "s = %" + maxValueSize + "s\n"; String format = "%-" + maxKeySize + "s = %s\n"; Enumeration<Object> keys2 = myProps.keys(); if (!keys2.hasMoreElements()) sb.append("*** no properties to print ***\n"); while (keys2.hasMoreElements()) { String key = (String) keys2.nextElement(); String value = myProps.getProperty(key); formatter.format(format, key, value); } return sb.toString(); } }