java - (Solved) How to add Strings to a LinkedHashSet? -


linkedhashset lhs = new linkedhashset(); lhs.add("beta"); 

when compiling above (tutorialspoint uses similar approach), error:

the method add(string) undefined type linkedhashset

and if it's generic (which think class declaration):

linkedhashset<string> lhs = new linkedhashset<string>(); lhs.add("beta"); 

then error:

the type linkedhashset not generic; cannot parameterized arguments

from java docs, seems linkedhashset should work generic version because extends hashset, , hashset works add().

how add string linkedhashset? need make own overloaded add() method include strings?

see whole program here

looking @ code:

class linkedhashset {      public static void main(string[] args) {         //linkedhashset<string> lhs = new linkedhashset<string>();         linkedhashset lhs = new linkedhashset();          lhs.add("beta");         lhs.add("alpha");         lhs.add("eta");         lhs.add("gamma");         lhs.add("epsilon");         lhs.add("omega");          system.out.println(lhs);     } } 

the class name containing code named linkedhashset, hides java.util.linkedhashset. class has no add method, , no generic type parameter. hence errors.

you should rename it. , should use generic declaration (linkedhashset<string> lhs = new linkedhashset<string>(); or set<string> lhs = new linkedhashset<>();).


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -