arraylistdemo.java
来自「JAVA的一些基础教程」· Java 代码 · 共 41 行
JAVA
41 行
import java.util.ArrayList;
import java.util.Iterator;
public class ArrayListDemo
{
public static void main( String[] args )
{
ArrayList arrayList = new ArrayList();
arrayList.add( new Integer( 1 ) );
arrayList.add( new Integer( 2 ) );
arrayList.add( new Integer( 3 ) );
arrayList.add( new Integer( 4 ) );
arrayList.add( new Integer( 5 ) );
arrayList.add( new Integer( 6 ) );
arrayList.add( new Integer( 7 ) );
arrayList.add( new Integer( 8 ) );
arrayList.add( new Integer( 9 ) );
arrayList.add( new Integer( 10 ) );
for( int i=0; i<arrayList.size(); i++ )
{
System.out.print( i + " = " + arrayList.get( i ) +"\t" );
}
arrayList.remove( 5 );
arrayList.set( 5, new Integer( 28 ) );
arrayList.add(new Integer(11));
for( Iterator i=arrayList.iterator(); i.hasNext(); )
{
Integer integer = ( Integer )i.next();
System.out.print( integer +"\t");
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?