ArrayList -(2022-05-31)

将拼接的字符串转为集合

String vehicleIds =1,2,3,4;
List<Integer> ids = Arrays.stream(vehicleIds.split(",")).map(Integer::parseInt).collect(Collectors.toList());

Collections.synchronizedList()构造一个线程安全的对象

List<Integer> success = Collections.synchronizedList(new ArrayList<>());

toHexString()方法

长类toHexString()方法 (Long class toHexString() method)
toHexString() method is available in java.lang package.

toHexString()方法在java.lang包中可用。

toHexString() method is used to represent a hexadecimal string of the given parameter [value] of long type as an unsigned long in base 16.

toHexString()方法用于将long类型给定参数[value]的十六进制字符串表示为以16为基数的无符号long。

toHexString() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.

toHexString()方法是一个静态方法,也可以使用类名进行访问,并且如果我们尝试使用类对象访问该方法,那么我们也不会收到错误。

toHexString() method does not throw an exception at the time of conversion from long integer to Hexadecimal string.

从长整数转换为十六进制字符串时, toHexString()方法不会引发异常。

StringUtils中常用方法leftPad(),rightPad(),center()

左侧填充:

leftPad():

StringUtils.leftPad(String str,int size);

StringUtils.leftPad(String str,int size,String padStr);

右侧填充:

rightPad():

StringUtils.rightPad(String str,int size);

StringUtils.rightPad(String str,int size,String padStr);

中间填充:

center():

StringUtils.center(String str, int size);

StringUtils.center(String str, int size, String padString);
例:

StringUtils.center("abcdef", 20);

返回结果(左右各7个空格):abcdef

StringUtils.center("abcdef", 20,"*_");

返回结果:*_*_*_abcdef*_*_*_*_

StringUtils.leftPad("abc", 10, "*");

返回结果:*******abc

StringUtils的isNotBlank方法

Str为空白或者null时,isNotBlank返回falseStr的length>0时,isNotBlank返回true

CollectionUtils.isEmpty

1: 判断集合是否为空:
  CollectionUtils.isEmpty(null): true
  CollectionUtils.isEmpty(new ArrayList()): true  
  CollectionUtils.isEmpty({a,b}): false

  例2: 判断集合是否不为空:
  CollectionUtils.isNotEmpty(null): false
  CollectionUtils.isNotEmpty(new ArrayList()): false
  CollectionUtils.isNotEmpty({a,b}): true

emptyList()方法的使用

通过java.util.Collections.emptyList()方法的相关源码可以得知它实际上就是返回了一个空的List,但是这个List和我们平时常用的那个List是不一样的。这个方法返回的List是Collections类的一个静态内部类,它继承AbstractList后并没有实现add()、remove()等方法,因此这个返回值List并不能增加删除元素。

既然这个List不能进行增删操作,那么它有何意义呢?
这个方法主要目的就是返回一个不可变的列表,使用这个方法作为返回值就不需要再创建一个新对象,可以减少内存开销。并且返回一个size为0的List,调用者不需要校验返回值是否为null,所以建议使用这个方法返回可能为空的List。

redisTemplate.opsForValue().increment(key,1) 自增值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

单眼皮女孩i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值