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

网站建设与技术团队长沙做网站建设公司哪家好

网站建设与技术团队,长沙做网站建设公司哪家好,鲜花网站建设文档,网站建设源代码怎么搭建一、List列表与对象数组 List列表中存储对象#xff0c;如ListInteger、ListString、ListPerson#xff0c;对象数组中同样存储相应的对象#xff0c;如Integer[]、String[]、Person[]#xff0c;对象数组与对象List的转换可通过如下方式实现如ListInteger、ListString、ListPerson对象数组中同样存储相应的对象如Integer[]、String[]、Person[]对象数组与对象List的转换可通过如下方式实现 一对象List转对象数组 1、toArray()方法 直接调用对象List的toArray()方法转换为对象数组该方法的参数是T[]因此需要传入对应的对象数组构造函数指定数组的长度如下所示 1 2 3 ArrayListInteger integersList new ArrayList(Arrays.asList(1,2,3)); // 1、toArray()方法 Integer[] integersArrau integersList.toArray(new Integer[integersList.size()]); // 2、toArray()方法等价于上面的用法即0会自动替换为size() Integer[] integersArrau integersList.toArray(new Integer[0]); ​​​​​​​ 2、Stream流的toArray()方法 通过Stream流的toArray()方法传入参数是对应对象的构造方法的方法引用使用方式如下所示 1 2 3 ArrayListInteger integersList new ArrayList(Arrays.asList(1,2,3)); // 2、Stream流的toArray()方法 Integer[] integersArray2 integersList.stream().toArray(Integer[]::new); 这个toArray()方法是Stream类下的该方法说明如下所示 /*** Returns an array containing the elements of this stream, using the* provided {code generator} function to allocate the returned array, as* well as any additional arrays that might be required for a partitioned* execution or for resizing.** pThis is a a hrefpackage-summary.html#StreamOps relexternal nofollow terminal* operation/a.** apiNote* The generator function takes an integer, which is the size of the* desired array, and produces an array of the desired size. This can be* concisely expressed with an array constructor reference:* pre{code* Person[] men people.stream()* .filter(p - p.getGender() MALE)* .toArray(Person[]::new);* }/pre** param A the element type of the resulting array* param generator a function which produces a new array of the desired* type and the provided length* return an array containing the elements in this stream* throws ArrayStoreException if the runtime type of the array returned* from the array generator is not a supertype of the runtime type of every* element in this stream*/ A A[] toArray(IntFunctionA[] generator); 该方法传入一个函数式接口该接口对应一个方法引用作用是创建一个新的指定类型和长度的数组因此我们传入的参数就是一个Integer[]数组的构造方法的方法引用最终得到的也就是一个Integer[]数组。 3、for循环 过于简单不再赘述。 二、对象数组转对象List 1、使用Arrays.asList() 该方法通过传入一个对象数组最后转换为一个对象List如下所示 1 2 3 Integer[] integersArray {1, 2, 3}; // 1、使用Arrays.asList() ListInteger integersList Arrays.asList(integersArray); asList方法传入的参数是一个可变参数因此既可以传入多个参数也可以传入一个数组如下所示 /*** Returns a fixed-size list backed by the specified array. (Changes to* the returned list write through to the array.) This method acts* as bridge between array-based and collection-based APIs, in* combination with {link Collection#toArray}. The returned list is* serializable and implements {link RandomAccess}.** pThis method also provides a convenient way to create a fixed-size* list initialized to contain several elements:* pre* Listlt;Stringgt; stooges Arrays.asList(Larry, Moe, Curly);* /pre** param T the class of the objects in the array* param a the array by which the list will be backed* return a list view of the specified array*/ SafeVarargs SuppressWarnings(varargs) public static T ListT asList(T... a) {return new ArrayList(a); } 2、使用Collections.addAll() 通过Collections集合类的static方法将一个对象数组转换为对象List注意首先要创建出一个对象List使用方式如下所示 1 2 3 4 Integer[] integersArray {1, 2, 3}; // 2、使用Collections.addAll() ArrayListInteger integersList2 new ArrayList(); Collections.addAll(integersList2,integersArray); 3、使用Stream中的Collector JDK8之后可以使用Stream流来执行转换操作通过Stream流的终结操作collect来指定将要转换得到的List 1 2 3 Integer[] integersArray {1, 2, 3}; // 3、使用Stream中的Collector ListInteger integersList3 Arrays.stream(integersArray).collect(Collectors.toList()); 4、for循环 过于简单不再赘述。 二、List列表与基本数据类型数组 上面我们介绍了对象List列表与对象数组之间的转换但是有些情况需要直接将对象List转换为基本数据类型数组如ListInteger转int[]这种情况下面详细介绍。 一、对象List转基本数据类型数组 1、Stream流执行转换 通过Stream流执行转换如ListInteger转换为int[]通过Stream流的mapToInt()可将每个Integer转换为int再输出为int数组如下所示 1 2 3 4 5 6 ArrayListInteger integersList new ArrayList(Arrays.asList(1,2,3)); // 1、Stream流执行转换 // 方法引用 int[] arrays1 integersList.stream().mapToInt(Integer::intValue).toArray();  //需要先用mapToInt进行转换 // 2、 lambda表达式 int[] arrays2 integersList.stream().mapToInt(i - i).toArray(); 2、for循环 过于简单不再赘述。 二、基本数据类型数组转对象List 1、Stream流转换 以int[]数组来举例通过Stream流的mapToObj()方法先将int[]数组中每个int值转换为Integer包装类再通过collect执行终结操作转换为Integer的List。 int[] integersArray {1, 2, 3}; // 1、Stream流转换 需要先用mapToObj进行转换 ListInteger integersList Arrays.stream(integersArray).mapToObj(Integer::new).collect(Collectors.toList()); 2、for循环 for循环是最简单、好用的方式不再赘述。 注意二维数组中的 list.toArray(array) 方法不能用于一维的 int[] 中。 因为 toArray() 方法的参数是范型对象而 int 是标准数据类型。可以用 Interger[]来实现
http://www.w-s-a.com/news/958818/

相关文章:

  • 成品网站是什么意思沈阳seo推广
  • 购物网站后台流程图昆明官网seo技术
  • 创建自己网站全网零售管理系统
  • 江苏省建设厅网站建筑电工证wordpress收费插件大全
  • 北京中国建设银行招聘信息网站宁德蕉城住房和城乡建设部网站
  • 泉州做网站优化哪家好wordpress站点预览
  • 创建门户网站一页网站首页图如何做
  • 服装手机商城网站建设sns社交网站有哪些
  • 无锡工程建设招标网站怎么自己建设公司网站
  • 哪个网站可以学做咸菜安卓软件开发需要学什么软件
  • 自有网站建设的团队遂宁市建设局网站
  • 网站建设哪个好一些网站内容导出
  • 什么网站的页面做的比较好看网上做平面设计的网站
  • 网站建设单选网站建设学校培训学校
  • 可以做app的网站logo设计在线生成免费标小智
  • 网站变更备案做酒类网站
  • 网站必须要备案吗东莞市非凡网站建设
  • 太原建网站公司网站设计的流程是怎样的
  • 网站开发交易平台北京网站建设的价格低
  • 捷克注册公司网站搜索引擎广告推广
  • 网站的实用性青岛九二网络科技有限公司
  • 广东备案网站网站反链如何做
  • 做网站的实施过程企业建设H5响应式网站的5大好处6
  • ps制作个人网站首页景安搭建wordpress
  • 常德建设网站制作网站建设推广是什么工作
  • 长春服务好的网站建设百度推广话术全流程
  • 做的网站浏览的越多越挣钱基于jsp的网站开发开题报告
  • 好的做问卷调查的网站好网站调用时间
  • 广州微网站建设平台阿里云国外服务器
  • 如何把做好的网站代码变成网页wordpress shortcode土豆 视频