collectiondemo.java

来自「电子工业出版社出版的《java2应用开发指南》配套光盘源代码」· Java 代码 · 共 28 行

JAVA
28
字号
//CollectionDemo.java
import java.util.*;

public class CollectionDemo
{
	public static void main( String[] args )
	{
		String strMonths[]={
			"一月","二月","三月",
			"四月","五月","六月",
			"七月","八月","九月",
			"十月","十一月","十二月"
		};
		//get count of months
		int nMonthLen= strMonths.length;
		//create arrayList object
		Collection months= new ArrayList();
		//pub months value to arraylist object
		for( int i=0; i< nMonthLen; i++){
			months.add(strMonths[i]);
		}
		//print all element in arraylist
		Object s[] = months.toArray();
		for( int i=0; i< s.length; i++ ){
			System.out.println(s[i].toString());
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?