java 集合的使用 (一)

时间:2021-03-14 21:23:24

1、使用整型列表

List<int> lstInt=new List<int>();

结果不对,报的错误是:Syntax error, insert "Dimensions" to complete ReferenceType

然后百度之:使用列表时,必须使用引用类型,不能使用基本类型的int

改成:

List<Integer> lstInt=new List<Integer>();

时报错:Cannot instantiate the type List<Integer>

再百度:List<int> lstInt=new  ArrayList<Integer>(); 写成这样才对。

2、使用List<String>

List<String> lstStr=new LinkedList<String>();

3、使用Map

引入import java.util.HashMap;

java语句:Map<String, Object> map = new HashMap<>();