Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 搜索字符数组列出特定字符_Java_Arrays_Arraylist_Char - Fatal编程技术网

Java 搜索字符数组列出特定字符

Java 搜索字符数组列出特定字符,java,arrays,arraylist,char,Java,Arrays,Arraylist,Char,我需要{'a','u','o'}的最终字符数组。但现在,错误为 线程“main”java.lang.UnsupportedOperationException中的异常位于 java.util.AbstractList.remove(未知源代码)位于 jayakumar.test1.DiffCharArray.main(DiffCharArray.java:67) Character[]c={'a','b','c','e'}; 字符[]p={'b','c','e','u','o'}; //List

我需要
{'a','u','o'}
的最终字符数组。但现在,错误为

线程“main”java.lang.UnsupportedOperationException中的异常位于 java.util.AbstractList.remove(未知源代码)位于 jayakumar.test1.DiffCharArray.main(DiffCharArray.java:67)

Character[]c={'a','b','c','e'};
字符[]p={'b','c','e','u','o'};
//List fl=新的ArrayList(Arrays.asList(c));
List fl=数组。asList(c);
用于(字符x:p)
{
系统输出println(x);
如果(fl.contains(x))
{
//System.out.println(“你好”);
fl.remove(x);
}
其他的
{
fl.add(x);
}
}
系统输出打印LN(fl);
List fl=Arrays.asList(c)
这将创建一个由数组支持的
列表
,因此您无法在此列表中添加或删除,请使用
List fl=newarraylist(Arrays.asList(c))

List fl=Arrays.asList(c)
这将创建一个由数组支持的
列表
,因此您无法在此列表中添加或删除,请使用
List fl=newarraylist(Arrays.asList(c))

数组。由于List
返回一个不可变的集合,您需要将此集合包装到另一个列表中
new ArrayList(fl)

数组。由于List
返回一个不可变的集合,您需要将此集合包装到另一个列表中
newarraylist(fl)

Arrays.asList()
返回不可变列表。您应该取消注释
listfl=newarraylist(Arrays.asList(c))行和注释
List fl=Arrays.asList(c)

Character[]c={'a','b','c','e'};
字符[]p={'b','c','e','u','o'};
List fl=新的ArrayList(Arrays.asList(c));
//List fl=数组。asList(c);
用于(字符x:p)
{
系统输出println(x);
如果(fl.contains(x))
{
//System.out.println(“你好”);
fl.remove(新字符(x));
}
其他的
{
fl.add(x);
}
}
系统输出打印LN(fl);
您应该在remove()方法中传递char的wrapper对象,该字符的其他明智的ascii代码将被视为索引。因此会有歧义。

数组。asList()
返回不可变列表。您应该取消注释
listfl=newarraylist(Arrays.asList(c))行和注释
List fl=Arrays.asList(c)

Character[]c={'a','b','c','e'};
字符[]p={'b','c','e','u','o'};
List fl=新的ArrayList(Arrays.asList(c));
//List fl=数组。asList(c);
用于(字符x:p)
{
系统输出println(x);
如果(fl.contains(x))
{
//System.out.println(“你好”);
fl.remove(新字符(x));
}
其他的
{
fl.add(x);
}
}
系统输出打印LN(fl);

您应该在remove()方法中传递char的wrapper对象,该字符的其他明智的ascii代码将被视为索引。因此会出现歧义。

请正确设置代码和执行选项文本的格式。只是为了验证-您正在尝试为
c
创建同样出现在
p
中的字符列表?请帮助我一些。我只需要这两个字符数组中的a,u,o字符[]c={'a','b','c','e'};字符[]p={'b','c','e','u','o'};请正确设置代码和执行选项文本的格式。只是为了验证-您正在尝试为
c
创建同样出现在
p
中的字符列表?请帮助我。我只需要这两个字符数组中的a,u,o字符[]c={'a','b','c','e'};字符[]p={'b','c','e','u','o'}@Jayakumar刚刚注意到你的
p
包含5个字符,而
c
包含4个字符,这就是为什么你会得到
java.lang.IndexOutOfBoundsException
@Ramanlfc NO。它会抛出IOOE异常,因为remove()方法将字符的ascii代码作为index@Jayakumar刚刚注意到您的
p
包含5个字符,而
c
包含4个字符,这就是为什么您会得到
java.lang.IndexOutOfBoundsException
@Ramanlfc NO。它将抛出IOOE异常,因为remove()方法将字符的ascii代码作为索引
Character[] c = {'a','b','c','e'};
Character[] p = {'b', 'c','e','u','o'};
//List<Character> fl = new ArrayList(Arrays.asList(c));
List<Character> fl = Arrays.asList(c);
for(char x : p)
{
System.out.println(x);
if(fl.contains(x))
{
//System.out.println("hello");
fl.remove(x);
}
else
{
fl.add(x);
}
}
System.out.println(fl);
       Character[] c = {'a','b','c','e'};
        Character[] p = {'b', 'c','e','u','o'};
        List<Character> fl = new ArrayList(Arrays.asList(c));
        //List<Character> fl = Arrays.asList(c);
        for(char x : p)
        {
        System.out.println(x);
        if(fl.contains(x))
        {
        //System.out.println("hello");
        fl.remove(new Character(x));
        }
        else
        {
        fl.add(x);
        }
        }
        System.out.println(fl);