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

签订网站建设合同应注意网站合同需要注意什么呢

签订网站建设合同应注意,网站合同需要注意什么呢,怎样给网站做推广,个人网站建设培训一、List列表与对象数组 List列表中存储对象&#xff0c;如List<Integer>、List<String>、List<Person>&#xff0c;对象数组中同样存储相应的对象&#xff0c;如Integer[]、String[]、Person[]&#xff0c;对象数组与对象List的转换可通过如下方式实现&…

一、List列表与对象数组

List列表中存储对象,如List<Integer>List<String>List<Person>,对象数组中同样存储相应的对象,如Integer[]、String[]、Person[],对象数组与对象List的转换可通过如下方式实现:

(一)对象List转对象数组

1、toArray()方法

直接调用对象List的toArray()方法转换为对象数组,该方法的参数是T[],因此需要传入对应的对象数组构造函数,指定数组的长度,如下所示:

1

2

3

ArrayList<Integer> 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

ArrayList<Integer> 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.** <p>This is a <a href="package-summary.html#StreamOps" rel="external 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(IntFunction<A[]> generator);

该方法传入一个函数式接口,该接口对应一个方法引用,作用是创建一个新的指定类型和长度的数组,因此我们传入的参数就是一个Integer[]数组的构造方法的方法引用,最终得到的也就是一个Integer[]数组。

3、for循环

过于简单,不再赘述。

(二)、对象数组转对象List

1、使用Arrays.asList()

该方法通过传入一个对象数组,最后转换为一个对象List,如下所示:

1

2

3

Integer[] integersArray = {1, 2, 3};

// 1、使用Arrays.asList()

List<Integer> 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}.** <p>This method also provides a convenient way to create a fixed-size* list initialized to contain several elements:* <pre>*     List&lt;String&gt; 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> List<T> 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()

ArrayList<Integer> 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

List<Integer> integersList3 = Arrays.stream(integersArray).collect(Collectors.toList());

4、for循环

过于简单,不再赘述。

二、List列表与基本数据类型数组

上面我们介绍了对象List列表与对象数组之间的转换,但是有些情况需要直接将对象List转换为基本数据类型数组,如List<Integer>int[]这种情况,下面详细介绍。

(一)、对象List转基本数据类型数组

1、Stream流执行转换

通过Stream流执行转换,如List<Integer>转换为int[],通过Stream流的mapToInt()可将每个Integer转换为int,再输出为int数组,如下所示:

1

2

3

4

5

6

ArrayList<Integer> 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进行转换
List<Integer> integersList = Arrays.stream(integersArray).mapToObj(Integer::new).collect(Collectors.toList());

2、for循环

for循环是最简单、好用的方式,不再赘述。

注意,二维数组中的 list.toArray(array) 方法不能用于一维的 int[] 中。

因为 toArray() 方法的参数是范型对象,而 int 是标准数据类型。可以用 Interger[]来实现

http://www.yayakq.cn/news/263982/

相关文章:

  • 柳州网站建设找哪家手机pc微信三合一网站
  • 产品详情页面设计自己怎么做网站优化
  • 网站建设有哪些困难app 官方网站 案例
  • 深圳网站定制设计百度网页版网址
  • 媒体网站 建设网络强国wordpress获取侧边栏
  • 网页网站建设的pptwordpress主题怎么选
  • 郑州自建网站wordpress 添加图片
  • 养殖p2p网站建设呼和浩特网站优化公司
  • lnmp wordpress建设多网站佛山设计网站设计价格
  • 哪些网站是用h5做的浦东网站建设公司
  • 广州企业网站建设电话wordpress 装饰插件
  • 北京外贸网站优化小学文化学网站开发
  • 洛阳做网站哪家好农业网站建设的特点是
  • 东莞专业做网站建设服务做网站需要交钱吗
  • 负责公司网站产品的开发及整理网站设置为应用程序
  • 怎么清理网站后门文件微信开发公司怎么样
  • 房屋建设设计网站公司建立网站怎么做分录
  • 在wordpress主页显示商品广州网站建设十年乐云seo
  • dedecms 招聘网站超链接网站怎么做
  • 江西省赣州市中考分数线2021苏州谷歌seo
  • 韶关东莞网站建设wordpress登录后转到wp首页
  • 绵阳力嘉信息网站建设公司旅游网站制作教程
  • 给个网站2022年手机上能用的企业宣传方案模板
  • 站长统计ios开发网页需要哪些技术
  • 网站制作 牛商网个人如何建立微信公众号
  • 阅读网站模板下载wap网站 趋势分析
  • 浙江省城乡和建设厅网站促销方案
  • 广州在建火车站在哪里网站是否开启gzip
  • 多语种网站制作会展网站建设成功的原因
  • 个体可以做几个网站凡科快图官网下载