简体   繁体   English

java 输入和 output 语法(简单)

[英]java input and output syntax (Simple)

I have this import statement:我有这个导入声明:

import java.util.List

Input:输入:

public class solution{ List<String> words (String text, List<String> bannedWords) {//BodyOfMethod } }

expected Output: list of strings预期 Output:字符串列表

My code:我的代码:

HashSet<String> bannedWords = new HashSet<>();
HashMap<String, Integer> validWordsCount = new HashMap<>();

List<Character> result = List<>();

It says error can't find symbol for the lines above.它说错误找不到上面几行的符号。 My syntax is wrong (I think it's out dated, from an old tutorial).我的语法错误(我认为它已经过时了,来自旧教程)。 Can I write it as Map instead of HashMap?我可以把它写成 Map 而不是 HashMap 吗?

Can someone please tell me the correct syntax for the the variable to the input and output?有人可以告诉我输入变量和 output 的正确语法吗?

HashSet<String> bannedWords = new HashSet<>();
HashMap<String, Integer> validWordsCount = new HashMap<>();

List<Character> result = List<>();

Typically you would type the variables as the interface types ( Set , Map , List ), and instantiate them with a particular implementation class ( HashSet , HashMap , ArrayList ).通常,您会将变量键入为接口类型( SetMapList ),并使用特定实现ArrayListHashSetHashMap )实例化它们。 See What does it mean to “program to an interface”?请参阅“编程到接口”是什么意思?

So this would be:所以这将是:

Set<String> bannedWords = new HashSet<>();
Map<String, Integer> validWordsCount = new HashMap<>();

List<Character> result = ArrayList<>();

All of these types can be imported from java.util , eg所有这些类型都可以从java.util导入,例如

import java.util.*;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM