Java examples for java.lang:String Array
Returns a String with the array printed as formatted text
/*//w w w. j av a2s . com Copyright 1996-2008 Ariba, Inc. 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. $Id: //ariba/platform/util/core/ariba/util/core/ArrayUtil.java#9 $ */ import java.io.PrintStream; import java.util.List; public class Main{ public static void main(String[] argv) throws Exception{ String header = "java2s.com"; String args = "java2s.com"; System.out.println(formatArray(header,args)); } /** Returns a String with the array printed as formatted text @param header a header to prefix the list with @param args the array of Strings to print @return a String with the array printed as formatted text. @aribaapi private */ public static String formatArray(String header, String args[]) { if (args == null) { return Fmt.S("%s (null)", header); } if (args.length == 0) { return Fmt.S("%s (<empty>)", header); } FormatBuffer retval = new FormatBuffer(); Fmt.B(retval, "%s", header); for (int i = 0; i < args.length; i++) { Fmt.B(retval, " args[%s] = (%s)", Constants.getInteger(i), args[i]); } return retval.toString(); } }