[英]java input and output syntax (Simple)
我有這個導入聲明:
import java.util.List
輸入:
public class solution{ List<String> words (String text, List<String> bannedWords) {//BodyOfMethod } }
預期 Output:字符串列表
我的代碼:
HashSet<String> bannedWords = new HashSet<>();
HashMap<String, Integer> validWordsCount = new HashMap<>();
List<Character> result = List<>();
它說錯誤找不到上面幾行的符號。 我的語法錯誤(我認為它已經過時了,來自舊教程)。 我可以把它寫成 Map 而不是 HashMap 嗎?
有人可以告訴我輸入變量和 output 的正確語法嗎?
HashSet<String> bannedWords = new HashSet<>();
HashMap<String, Integer> validWordsCount = new HashMap<>();
List<Character> result = List<>();
通常,您會將變量鍵入為接口類型( Set
、 Map
、 List
),並使用特定實現ArrayList
( HashSet
、 HashMap
)實例化它們。 請參閱“編程到接口”是什么意思?
所以這將是:
Set<String> bannedWords = new HashSet<>();
Map<String, Integer> validWordsCount = new HashMap<>();
List<Character> result = ArrayList<>();
所有這些類型都可以從java.util
導入,例如
import java.util.*;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.