FileDocCategorySizeDatePackage
VarargsTester.javaAPI DocExample1426Sat Apr 24 08:26:30 BST 2004com.oreilly.tiger.ch05

VarargsTester

public class VarargsTester extends Object

Fields Summary
Constructors Summary
public VarargsTester()

  
Methods Summary
private int[]getListOfNumbers()

    int[] numbers = new int[] {0, 2, 4, 6, 8, 10, 9, 7, 5, 3, 1};
    return numbers;
  
public static voidmain(java.lang.String[] args)

    try {
      VarargsTester tester = new VarargsTester();

      tester.testMaxMethod(System.out);
      tester.testPrintMethod(System.out);
      tester.testArrayArgs(System.out);
    } catch (IOException e) {
      e.printStackTrace();
    }
  
private java.lang.Stringprint(java.lang.Object values)

    StringBuilder sb = new StringBuilder();
    for (Object o : values) {
      sb.append(o.toString())
        .append(" ");
    }
    return sb.toString();
  
public voidtestArrayArgs(java.io.PrintStream out)

    Object[] obj = new String[] {"Hello", "to", "all", "of", "you"};

    out.printf("%s\n", obj);
    out.printf("%s\n", (Object)obj);
  
public voidtestMaxMethod(java.io.PrintStream out)

    int[] numbers = getListOfNumbers();

    int max = MathUtils.max(numbers);
    out.println("Max of list is: " + max);
  
public voidtestPrintMethod(java.io.PrintStream out)

    out.println(print("foo", 23, -12, 1.23, getListOfNumbers()));