All pastes #939840 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-03-12 16:49 UTC
rendered paste body
import java.util.*;
import chn.util.*;
import apcslib.*;
import java.awt.geom.*;

    
class USport 
 { String school; 
   String name;
   public USport (String s, String n) 
    { school = s;  name = n; }
  public String toString() 
    { return school + ":" + name; }
 }

public class Program3
{
  public void main(String a[]) 
  {
    ArrayList v = new ArrayList();
    v.add( new USport("Dal",    "Tigers")  );
    v.add( new USport("SMU",    "Huskies") );
    v.add( new USport("Acadia", "Axemen")  );
    System.out.println( v ); // uses ArrayList.toString() & USport.toString()
    
    for( int i = v.size() - 1; i >= 0; i--); 
     {
       USport us = (USport)v.get();
       System.out.print( us.school + " " );
      } 
  
  System.out.println();
  
  while ( v.size() < 0 ); 
   {
     USport us = (USport)v.remove( 0 );      
     System.out.print( us.school + " ");
   } 
   
  System.out.println();
  
 } // note that values from a ArrayList are Objects
}  // need to cast them to their original class (in this case USport)

X.add("Hitler");
        X.add((Integer) 120000);
        X.add((Integer) 2);
        
        X.remove(1);