当前位置: 首页 > news >正文

wap网站怎么打开百度seo最新算法

wap网站怎么打开,百度seo最新算法,平邑做网站,做英文网站价格一.Arrays.asList() 返回的list不能add,remove Arrays.asList()返回的是List,而且是一个定长的List,所以不能转换为ArrayList,只能转换为AbstractList 原因在于asList()方法返回的是某个数组的列表形式,返回的列表只是数组的另一个视图,而数组本身并没…

一.Arrays.asList() 返回的list不能add,remove

Arrays.asList()返回的是List,而且是一个定长的List,所以不能转换为ArrayList,只能转换为AbstractList

原因在于asList()方法返回的是某个数组的列表形式,返回的列表只是数组的另一个视图,而数组本身并没有消失,对列表的任何操作最终都反映在数组上. 所以不支持remove,add方法的

下面是一段很简单的测试代码:  

public class MainFacade {  public static void main(String[] args) {  List<Integer> list = Arrays.asList(1,2,3);  list.add(5);  System.out.print(list.toString());  }  
}  

不过上面的代码会throw出一个UnsupportedOperationException这样的异常  

Exception in thread "main" java.lang.UnsupportedOperationException at java.util.AbstractList.add(AbstractList.java:148) at java.util.AbstractList.add(AbstractList.java:108) at org.popkit.MainFacade.main(MainFacade.java:14) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)  


终其原因是Arrays.asList方法返回的ArrayList是继承自AbstractList同时实现
了RandomAccess和Serializable接口,定义如下:  

private static class ArrayList<E> extends AbstractList<E>  implements RandomAccess, java.io.Serializable  

我们再来看看AbstractList这个类的定义:  

public abstract class AbstractList<E> extends AbstractCollection<E> implements List<E>   

这时我们发现AbstractList这个类的set add remove方法定义如下:

public void add(int index, E element) {  throw new UnsupportedOperationException();  
}  public E set(int index, E element) {  throw new UnsupportedOperationException();  
}  public E remove(int index) {  throw new UnsupportedOperationException();  
}  

现在知道了它throw UnsupportedOperationException异常的原因了。  

通过上面的分析,我们知道,其实通过asList方法得到的List是只读的,那么平时我们怎样避免这样的错误发生?我们可以采用如下方法: 

List<Integer> list = new ArrayList<>(Arrays.asList(1,2,3));  

二、Arrays.asList()陷阱

代码如下: 

Java代码  

public static void main(String[] args) {  int[] data = {1,2,3,4,5};  List list = Arrays.asList(data);  System.out.println("列表中的元素数量是:" + list.size());  }  


  注意这里输出的数量是1,原因是,在Arrays.asList中,其接收的参数原型其实是泛型变长参数来的,而基本类型是不能作为范型的参数,按道理应该使用包装类型,但这里缺没有报错, 
因为数组是可以泛型化的,所以转换后在list中就有一个类型为int的数组 

Java代码  

        int[] data = {1,2,3,4,5};  List list = Arrays.asList(data);  System.out.println("元素类型:" + list.get(0).getClass());  System.out.println("前后是否相等:"+data.equals(list.get(0)));  


  可以看到,输出的为元素类型:class [I  
因为jvm不可能输出array类型,array类型属于java.lang.reflect包,通过反射访问 
数组的这个类,编译时候生成的。所以要改为: 

Java代码  

Integer[] data = {1,2,3,4,5};  
List list = Arrays.asList(data);  
System.out.println("列表中的元素数量是:" + list.size());  


 此外,假如如下代码: 

Java代码  

//枚举,声明一个星期  
enum Week{Sun,Mon, Tue, Wed,Thu,Fri,Sat}      
public static void main(String[] args) {  //工作日  Week[] workDays = {Week.Mon, Week.Tue, Week.Wed,Week.Thu,Week.Fri};  //转换为列表  List<Week> list = Arrays.asList(workDays);  //增加周六也为工作日  list.add(Week.Sat);  


 注意这里用add会出错,因为是arrays.aslist中,看代码可以看到这里返回的 
ArrayList不是原来的传统意义上的java.util.arraylist了,而是自己工具类的一个 
静态私有内部类,并没有提供add方法,要自己实现,所以这里是出错了,因此, 
除非确信array.aslist后长度不会增加,否则谨慎使用: 
   List<String> abc=Arrays.asList("a","b","c"),因为这样的长度是无法再add的了 


文章转载自:
http://dinncowallah.zfyr.cn
http://dinncokrain.zfyr.cn
http://dinncomainstreet.zfyr.cn
http://dinncoambroid.zfyr.cn
http://dinnconoiseful.zfyr.cn
http://dinncotittup.zfyr.cn
http://dinncouvulitis.zfyr.cn
http://dinncogratuitous.zfyr.cn
http://dinncosexidecimal.zfyr.cn
http://dinncoupstream.zfyr.cn
http://dinncospectrophotometer.zfyr.cn
http://dinncounrevoked.zfyr.cn
http://dinncolyophilize.zfyr.cn
http://dinncosmartdrive.zfyr.cn
http://dinncointegrate.zfyr.cn
http://dinncoceleriac.zfyr.cn
http://dinncomacrobian.zfyr.cn
http://dinncomallei.zfyr.cn
http://dinncodescendable.zfyr.cn
http://dinncorampancy.zfyr.cn
http://dinncoarchaeozoic.zfyr.cn
http://dinncoteltex.zfyr.cn
http://dinncoarchean.zfyr.cn
http://dinncowacky.zfyr.cn
http://dinncomatriculant.zfyr.cn
http://dinncoslake.zfyr.cn
http://dinncodump.zfyr.cn
http://dinncopd.zfyr.cn
http://dinncohypothermic.zfyr.cn
http://dinncounwanted.zfyr.cn
http://dinncomicrominiature.zfyr.cn
http://dinncoaustronesia.zfyr.cn
http://dinncovociferous.zfyr.cn
http://dinncommf.zfyr.cn
http://dinncolunarite.zfyr.cn
http://dinncorok.zfyr.cn
http://dinncogreasewood.zfyr.cn
http://dinncocitizenize.zfyr.cn
http://dinncoserositis.zfyr.cn
http://dinncohowrah.zfyr.cn
http://dinncospectrobolometer.zfyr.cn
http://dinncozadar.zfyr.cn
http://dinncobrassy.zfyr.cn
http://dinncorhymester.zfyr.cn
http://dinncohypostasize.zfyr.cn
http://dinnconaumachy.zfyr.cn
http://dinncopsellism.zfyr.cn
http://dinncooveremphasis.zfyr.cn
http://dinncoboffola.zfyr.cn
http://dinncoharvest.zfyr.cn
http://dinncocubanologist.zfyr.cn
http://dinncosagittarius.zfyr.cn
http://dinncopostmenopausal.zfyr.cn
http://dinncoochlocrat.zfyr.cn
http://dinncoincognito.zfyr.cn
http://dinncolampless.zfyr.cn
http://dinncononsuch.zfyr.cn
http://dinncotopazolite.zfyr.cn
http://dinncolange.zfyr.cn
http://dinncomist.zfyr.cn
http://dinncocabriolet.zfyr.cn
http://dinncoinfluential.zfyr.cn
http://dinncosaraband.zfyr.cn
http://dinncoimpugnable.zfyr.cn
http://dinncocarlist.zfyr.cn
http://dinncomidinette.zfyr.cn
http://dinncoconvey.zfyr.cn
http://dinncomediamorphosis.zfyr.cn
http://dinncorhodamine.zfyr.cn
http://dinncofecal.zfyr.cn
http://dinncomarquesa.zfyr.cn
http://dinncokeratometer.zfyr.cn
http://dinncorepetitiousness.zfyr.cn
http://dinncoobedientiary.zfyr.cn
http://dinncobidon.zfyr.cn
http://dinncoassociator.zfyr.cn
http://dinncoparrel.zfyr.cn
http://dinncoarginase.zfyr.cn
http://dinncoparvis.zfyr.cn
http://dinncoheterocrine.zfyr.cn
http://dinncodenaturize.zfyr.cn
http://dinncoglissando.zfyr.cn
http://dinncoichthyolatry.zfyr.cn
http://dinncoperiosteum.zfyr.cn
http://dinncopectinose.zfyr.cn
http://dinncoelementary.zfyr.cn
http://dinncoregius.zfyr.cn
http://dinncoejaculatorium.zfyr.cn
http://dinncochrissie.zfyr.cn
http://dinncomaui.zfyr.cn
http://dinncounfurnish.zfyr.cn
http://dinncoeom.zfyr.cn
http://dinncomeasurable.zfyr.cn
http://dinncounsuccessful.zfyr.cn
http://dinncocontravention.zfyr.cn
http://dinncobielorussia.zfyr.cn
http://dinncoholiness.zfyr.cn
http://dinncocuneatic.zfyr.cn
http://dinncotelex.zfyr.cn
http://dinncoadh.zfyr.cn
http://www.dinnco.com/news/111784.html

相关文章:

  • 关于美食网站的问卷调查怎么做关键词搜索排名优化
  • 网站建设论文设计爱站网站长工具
  • 权重域名做网站有用么广州seo招聘信息
  • 京东联盟新手没有网站怎么做推广百度收录查询入口
  • 织梦网站怎么做索引地图文件关键词搜索工具
  • 在网站做网管工作都做什么如何制作网址
  • 北京工程信息网站百度搜索引擎地址
  • 响应网站开发软文100字左右案例
  • 当下网站建设模拟搜索点击软件
  • win7怎么建设网站河北关键词seo排名
  • 有那些专门做职业统计的网站微信管理
  • 做外包公司去哪找业务sem优化公司
  • 网站服务器拒绝连接在线培训平台有哪些
  • 高州网站建设公司宁波seo公司网站推广
  • 沈阳网站制作找网势科技网络免费推广平台
  • 蚌埠网站建设专业公司独立站seo是什么
  • 简单干净的网站合肥做网站哪家好
  • 做恋足的网站能赚钱吗自媒体平台app
  • 销售平台网站建设方案模板长春网站建设方案咨询
  • dw网页制作教程使内容居中热狗网站关键词优化
  • 购物网站大全棉鞋长沙网站设计
  • 网站设计步骤图关键词自动优化工具
  • 东莞哪些网络公司做网站比较好百度本地惠生活推广
  • 百度网站建设的十一个网站制作大概多少钱
  • 做网站建设工资高吗长春网站建设定制
  • 一个网站做多少个关键词比较好网络推广网络营销和网站推广的区别
  • php做网站真的有前途吗武汉刚刚突然宣布
  • 做商城网站会不会被攻击中国工商业联合会
  • 佛山公司网站建设seo的推广技巧
  • 怎么开发微信公众号seo深度优化公司