listtest.java
来自「金旭亮的java教案」· Java 代码 · 共 53 行
JAVA
53 行
// ListTest.java
// Class ListTest
public class ListTest {
public static void main( String args[] )
{
List objList = new List(); // create the List container
// Create objects to store in the List
Boolean b = Boolean.TRUE;
Character c = new Character( '$' );
Integer i = new Integer( 34567 );
String s = "hello";
// Use the List insert methods
objList.insertAtFront( b );
objList.print();
objList.insertAtFront( c );
objList.print();
objList.insertAtBack( i );
objList.print();
objList.insertAtBack( s );
objList.print();
// Use the List remove methods
Object removedObj;
try {
removedObj = objList.removeFromFront();
System.out.println(
removedObj.toString() + " removed" );
objList.print();
removedObj = objList.removeFromFront();
System.out.println(
removedObj.toString() + " removed" );
objList.print();
removedObj = objList.removeFromBack();
System.out.println(
removedObj.toString() + " removed" );
objList.print();
removedObj = objList.removeFromBack();
System.out.println(
removedObj.toString() + " removed" );
objList.print();
}
catch ( EmptyListException e ) {
System.err.println( "\n" + e.toString() );
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?