ComparatorTest - { Iterator itr = C.iterator( ); while(...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; i class ComparatorTest { static void sortListOfStringsByLength( List L ) { class Comp implements Comparator { public int compare( Object lhs, Object rhs ) { return ((String)lhs).length( ) - ((String)rhs).length( ); } } Collections.sort( L, new Comp( ) ); } static void printList( Collection C )
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { Iterator itr = C.iterator( ); while( itr.hasNext( ) ) System.out.println( itr.next( ) ); } public static void main( String [ ] args ) { LinkedList L = new LinkedList( ); L.add( "this" ); L.add( "thank" ); L.add( "the" ); sortListOfStringsByLength( L ); printList( L ); } }...
View Full Document

This document was uploaded on 06/13/2011.

Ask a homework question - tutors are online