集合的相关操作记录

1.给String数组添加值的方法

	List <String> data=new ArrayList<String>();

        String value="value";

        data.add(value)

        String [] toStrArr=list.toArray(new String[data.size()]);//转成数组

因为字符串数组不能单独添加值,所以可以先把值添加到list里,然后在把list转成字符串数组。


2.String数组转成list(需要导Arrays工具类的包)

String [] strArry=new String[] {"str1","str2"};

List toList=Arrays.asList(strArry);


3.Map遍历的方法

1)

Map map=new HashMap();//别忘记赋值
Iterator iterator=map.entrySet().iterator();

while (iterator.hasNext()) {
			Map.Entry entry = (Map.Entry)iterator.next();			

                        Object key=entry.getKey().toString();//得到键

			Object value=entry.getValue().toString();//得到值

			}


猜你喜欢

转载自blog.csdn.net/deronn/article/details/79040486