Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting compile error ,if try to compile with jdk 1.6.

 
Ashish Anil Khadilkar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried to compile following programme on jdk 1.6, but I have got error : javac ArrayListDemo2.java
ArrayListDemo2.java:5: '(' or '[' expected
ArrayList<String> data = new ArrayList<String>();
^
1 error
source code:
import java.util.*;

public class ArrayListDemo2 {
public static void main(String[] args) {
ArrayList<String> data = new ArrayList<String>();
data.add("hello");
data.add("goodbye");

// data.add(new Date()); This won't compile!

Iterator<String> it = data.iterator();
while (it.hasNext()) {
String s = it.next();
System.out.println(s);
}
}
}
I have set path to "jdk 1.6 /bin" . Could anyone please suggest me how to solve this.
 
Ashish Anil Khadilkar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it worked.I just removed the old path of jdk 1.4 from system variables (My computer/Environmental variables. thanks
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It won't compile because you defined ArrayList<String> data = new ArrayList<String>(), so data can only accept String and not Date.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic