0

Plzz help which type of error is this???

https://code.sololearn.com/cr3629mVjI1a/?ref=app

4th Sep 2021, 4:15 AM
Kajal Kumari
4 Antworten
+ 2
There is nothing wrong with the code. Just import Set and HashSet. import java.util.Set; import java.util.HashSet;
4th Sep 2021, 5:32 AM
Avinesh
Avinesh - avatar
+ 2
Izac Espinoza For clarification, there actually is nothing wrong with using; Set<Integer> values = new HashSet<Integer>(); and is usually the preferred way with collection types. It's a typical use of polymorphism. The only issue(s) I see from a glance at the code is the missing imports.
4th Sep 2021, 9:18 AM
ChaoticDawg
ChaoticDawg - avatar
0
So pretty much, you did'nt have the HASHSET object imported at the top of your code, and you declared the Hashset slightly wrong, here's the fixed code I hope it works for you :) /*Without this import, the program doesn't know what a hashset is, this just brings it into the picture so you can use it, "import java.util.*;" imports all java stuff you might need, so you don't have to do a bunch of import statements. */ import java.util.*; public class ShowCollection { public static void main(String[] args) { /*Here is where you messed up , you had declared the hashset like this: Set<Integer>values, the correct way is below */ HashSet<Integer>values=new HashSet<Integer>(); values.add(1); values.add(2); values.add(3); values.add(4); for(int x:values) { System.out.println(x); } } }
4th Sep 2021, 4:49 AM
Izac Espinoza
Izac Espinoza - avatar