浅谈Arrays.asList()方法的使用
更新时间:2017年02月02日 12:39:47 作者:52Hz
本文主要介绍了Arrays.asList()方法的使用。具有很好的参考价值,下面跟着小编一起来看下吧
首先,该方法是将数组转化为list。有以下几点需要注意:
(1)该方法不适用于基本数据类型(byte,short,int,long,float,double,boolean)
(2)该方法将数组与列表链接起来,当更新其中之一时,另一个自动更新
(3)不支持add和remove方法
上代码:
package com.hdu.test; import java.util.Arrays; import java.util.List; abstract public class AsllistTest { public static void main(String[] args) { String[] s = {"aa","bb","cc"}; List<String> strlist = Arrays.asList(s); for(String str:strlist){ System.out.println(str); } System.out.println("------------------------"); //基本数据类型结果打印为一个元素 int[] i ={11,22,33}; List intlist = Arrays.asList(i); for(Object o:intlist){ System.out.println(o.toString()); } System.out.println("------------------------"); Integer[] ob = {11,22,33}; List<Integer> oblist = Arrays.asList(ob); for(int a:oblist){ System.out.println(a); } System.out.println("------------------------"); } }
运行结果:
aa bb cc ------------------------ [I@15db9742 ------------------------ 22 ------------------------
请参考这篇文章:https://www.jb51.net/article/104399.htm
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持脚本之家!
相关文章
JDBC PreparedStatement Like参数报错解决方案
这篇文章主要介绍了JDBC PreparedStatement Like参数报错解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下2020-10-10Spring ApplicationContextAware 接口的作用及使用方式
Spring提供了许多回调接口,用于Bean生命周期中执行特定的操作,通过实现ApplicationContextAware接口,Spring提供了一种便捷的方式让 Bean获取对Spring容器的引用,本文介绍ApplicationContextAware接口的作用、使用方式,以及在实际应用中的常见场景,感兴趣的朋友一起看看吧2024-01-01
最新评论