数组转list的小知识

String phone = "a,b,c,d";
Arrays.asList(phone.split(","));
这个产生的是一个固定大小,不可变的数组,
是无法进行增加,删除操作的,作用有限 ,jdk里面解释为:

@SafeVarargs

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 Collection.toArray. The returned list is serializable and implements RandomAccess.

This method also provides a convenient way to create a fixed-size list initialized to contain several elements:

     List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");
Parameters:
a the array by which the list will be backed
Returns:
a list view of the specified array  //只是作为一种view形式
所以要进行操作要用这种:

Lists.newArrayList(phone.split(","));

@GwtCompatible(serializable=true)

Creates a mutableArrayList instance containing the given elements.

Note: if mutability is not required and the elements are non-null, use an overload of ImmutableList.of() (for varargs) or ImmutableList.copyOf(Object[]) (for an array) instead.

Parameters:
elements the elements that the list should contain, in order
Returns:
a new ArrayList containing those elements

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值