Java examples for java.lang:int Array
Write an array into a PrintStream.
/*//from www. j a v a 2 s .co m 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{ /** Write an array into a PrintStream. @param out a PrintStream to write the output to @param head a header to prefix the list with @param args the array of Strings to print @see #formatArray(String, String[]) @aribaapi private */ public static void printArray(PrintStream out, String head, String args[]) { out.println(formatArray(head, 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(); } }