• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic