// OrderedList.java // // Extracts a list of integers from a text file, one per line // and creates an ordered list using the add() method. import java.util.*; public class OrderedList { public static void main( String[] args ) { Scanner theFile = new Scanner( new File( "values.txt" ) ); Vector theList = new Vector(); while( theFile.hasNext() ) { int num = theFile.nextInt(); int i = 0; while( i < theList.size() && num > theList.elementAt( i ) ) i = i + 1; theList.add( i, num ); } theFile.close(); for( int i = 0; i < theList.size(); i++ ) System.out.print( theList.elementAt( i ) + " " ); System.out.println(); } }