zoukankan      html  css  js  c++  java
  • list的几种new方式比较ImmutableList

    数组的非空判断:

    -----数组的非空判断-----
    StringUtils.isNotBlank(array);

    list的非空判断:

    -----list的非空判断-----
    CollectionUtils.isNotEmpty(userEntityLists);

    new list的最新写法

    import com.google.common.collect.ImmutableList;

    List<String> subChannels = ImmutableList.<String>builder() .add("XHD") .add("RC") .add("WJ") .add("RCW") .build();

    或者

    import com.google.common.collect.Lists;
    
    ------new ArrayList()最新写法----------
    List<UserInfoCache> userInfoCaches = Lists.newArrayList();

    导包的时候会出现问题:

    google的很多常用库都在guava包中,所以需要在maven中的

    <properties>
    中间加上下面这行代码是为了指定guava的版本号
    <com.google.guava.version>18.0</com.google.guava.version>
    </properties>


    <dependency>
        <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>${com.google.guava.version}</version>
    </dependency>

    用properties的目的是因为:

    在spring的依赖中,我们需要引用一系列版本的spring,如版本1.2.6。每次都写不利于维护,所以提取出来。

    猜想:为什么要用这种方式来新建一个list,瞅瞅google的jar包源码:

    未完待续。。。

    over。。。

  • 相关阅读:
    2020软件工程作业05
    一、uart&tty驱动
    柔性数组使用备忘
    指针和数组备忘
    计算信息帧的校验和(备忘)
    Linux系统vim几个常见配置
    C语言实现过滤ASCII在0~127范围内的字符,并去除重复的字符
    extern "C"的用法
    strtol详解
    将一个十进制整数转换为二进制并输出
  • 原文地址:https://www.cnblogs.com/chenzeyong/p/7376292.html
Copyright © 2011-2022 走看看