Using HashSet<E> in Java 5.0

I desperately need help reading this API file

http://java.sun.com/j2se/1.5.0/docs/api/java/util/HashSet.html

I know how to use HashSet in Java1.4 but now its different and I get an error

Here's my code:

import java.io.*;

import java.util.HashSet.*;

importstatic java.lang.System.*;

publicclass HashsetExample{

publicstaticvoid main(String args[]){

HashSet bar =new HashSet();//define bar as a HashSet

bar.add("added");

}//end main

}//end class

Error I get at compile:

"HashsetExample.java:14: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.HashSet

bar.add("added");

^

1 warning

"

I know the "add(E)" has to do with HashSet defined in the API, but I cant make heads or tails of how to use it. How do you use HashSet in Java 1.5?

[1450 byte] By [andre2000a] at [2007-10-2 12:20:55]
# 1

import java.io.*;

import java.util.HashSet;

public class a {

public static void main(String args[]){

HashSet<String> bar = new HashSet<String>();

bar.add("added");

}//end main

}//end class

BIJ001a at 2007-7-13 9:10:26 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

Thanks! Helps alot!

I'm in a Data Structures class at UCSC.

I beat my head over this problem for hours!

Problems like that always end up simple fixes.

So another question. The HashSet is defined as a String type.

So does that mean I cannot add to it different objects?

like

bar.add(new Integer(1));

?

andre2000a at 2007-7-13 9:10:26 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
You may want to read http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
sundararajan.aa at 2007-7-13 9:10:26 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...