美文网首页
Arrays.asList()报错unsupportedoper

Arrays.asList()报错unsupportedoper

作者: 小火耳 | 来源:发表于2017-05-11 16:00 被阅读0次

    package org.geng.testPackage;

    import java.util.ArrayList;

    import java.util.Arrays;

    import java.util.List;

    publicclass AsListTest {

    public static void main(String[] args) {

    String testStr ="100,300,400,545,666";

    //java.util.Arrays$ArrayList 没有重写add(), remove()方法所以用注释掉的代码会报错

    //List test = Arrays.asList(testStr.split(","));

    List test =new ArrayList();//所以需要这么重新new一个ArrayList

    test.addAll(Arrays.asList(testStr.split(",")));

    test.remove("100");

    /*String s = "nu";

    System.out.println(Arrays.asList(s));

    */

    Integer[] payIds = {2,5,14,15};

    if(Arrays.asList(payIds).contains(15)){

    System.out.println("yes");

    }else{

    System.out.println("no");

    }

    }

    }

    相关文章

      网友评论

          本文标题:Arrays.asList()报错unsupportedoper

          本文链接:https://www.haomeiwen.com/subject/owkqattx.html