简体   繁体   中英

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

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?

Can someone please tell me the correct syntax for the the variable to the input and 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 ). 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

import java.util.*;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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