FileDocCategorySizeDatePackage
CompClass.javaAPI DocExample3303Mon Apr 06 18:10:26 BST 1998c08.newcollections

CompClass

public class CompClass extends Object implements Comparable

Fields Summary
private int
i
Constructors Summary
public CompClass(int ii)

 i = ii; 
Methods Summary
public intcompareTo(java.lang.Object o)

    // Implicitly tests for correct type:
    int argi = ((CompClass)o).i;
    if(i == argi) return 0;
    if(i < argi) return -1;
    return 1;
  
public static voidmain(java.lang.String[] args)

    CompClass[] a = new CompClass[20];
    for(int i = 0; i < a.length; i++)
      a[i] = new CompClass(
        (int)(Math.random() *100));
    print(a);
    Arrays.sort(a);
    print(a);
    int loc = Arrays.binarySearch(a, a[3]);
    System.out.println("Location of " + a[3] +
     " = " + loc);
  
public static voidprint(java.lang.Object[] a)

    for(int i = 0; i < a.length; i++)
      System.out.print(a[i] + " ");
    System.out.println();
  
public java.lang.StringtoString()

 return i + "";