gpt4 book ai didi

java - List.of 给出编译错误 "The method of(char, char, char, char, char, char) is undefined for the type List"

转载 作者:行者123 更新时间:2023-12-01 17:58:04 37 4
gpt4 key购买 nike

当我尝试运行以下代码时,List(.of) 无法编译并给出主题错误。

package collections;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class SetRunner {

public static void main(String[] args) {

List<Character> characters = **List.of**('A', 'Z', 'A', 'B', 'Z', 'F');

Set<Character> treeSet = new TreeSet<>(characters);
System.out.println("TreeSet" + characters);

Set<Character> linkedHashSet = new LinkedHashSet<>(characters);
System.out.println("LinkedHashSet" + characters);
}


}

最佳答案

对于旧版本的 Java,您可以这样做

List<Character> characters = Arrays.asList(new Character[]{'A', 'Z', 'A', 'B', 'Z', 'F'});

关于java - List.of 给出编译错误 "The method of(char, char, char, char, char, char) is undefined for the type List",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60682699/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com