I encountered a problem when I used editplus to write java files.
Copy the code code as follows:
import java.util.*;
class collection{
public static void main(String[] args) {
Collection c1=new ArrayList(25);
c1.add(new String("one"));
c1.add(new String("two"));
String s="three";
c1.add(s);
for (Iterator i=c1.iterator();i.hasNext();)
{
System.out.println(i.next());
}
}
}
Then I found the following reasons, which were transferred from others.
When compiling java source files, this problem may occur when you are using jdk1.5 or above. (Unchecked or unsafe operation used; recompile with -Xlint:unchecked.)
The reason is that the creation of collection classes in jdk1.5 is somewhat different from that in jdk1.4. The main reason is that generics are added in jdk1.5, which means that the data in the collection can be checked. Before jdk1.5, if the parameter type is not specified, the JDK 1.5 compiler will report an unchecked warning because it cannot check whether the given parameters meet the requirements, which does not affect the operation. Follow the prompts and compile by specifying parameters to cancel such warnings. Or specify type parameters for it.
Copy the code code as follows:
List temp = new ArrayList ();
temp.add("1");
temp.add("2");
Modify to
Copy the code code as follows:
List <String> temp = new ArrayList <String> ();
temp.add("1");
temp.add("2");
Then modify the code to
Copy the code code as follows:
import java.util.*;
class collection{
public static void main(String[] args) {
Collection<String> c1=new ArrayList<String>(25);
c1.add(new String("one"));
c1.add(new String("two"));
String s="three";
c1.add(s);
for (Iterator i=c1.iterator();i.hasNext();)
{
System.out.println(i.next());
}
}
}