4 Replies Latest reply: May 7, 2008 1:41 AM by 807601 RSS

    ArrayList

    807601
      Hi,
      I am now learning ArrayList. I wrote some program using netbeans3.6.
      Code:
      import java.util.*;
      public class ArrayListemo1 {
      public static void main(String args[]){
      ArrayList<String> al = new ArrayList<String>();
      ......................
      .......................
      }
      }

      While typing the statement ArrayList<String> al = new ArrayList<String>(); it gives error " '(' or '[' expected. Can not ressolve the symbol ArrayList".
      When i run the same program using netbeans 6.1 then it works properly. Then what is the problem for netbeans 3.6? Please help.
      Thank you.
        • 1. Re: ArrayList
          791266
          Netbeans 3.6 is really really old, and generics was added in Java 5, probably after Netbeans 3.6 was released.

          Kaj
          • 2. Re: ArrayList
            807601
            Hi.
            But in netbeans3.6 : when I wrote the following code, it works!

            import java.util.*;
            public class ArrayListDemo1 {

            public static void main(String[] args) {
            ArrayList al = new ArrayList();
            al.add(0,"1");
            al.add(1,"2");
            al.add(2,"3");
            al.add(3,"4");
            System.out.println("Contents of al = " + al);
            }
            }
            Please guide.
            • 3. Re: ArrayList
              791266
              Tree123 wrote:
              Hi.
              But in netbeans3.6 : when I wrote the following code, it works!
              That's because the class ArrayList has been available for very long, it's only generics that is new.

              Kaj
              • 4. Re: ArrayList
                807601
                Yes because the compiler you are using is probably 1.4 which does not have generics. The code that didn't compile contained generics. As soon as you removed the generics type stuff, your code compiled. Not too hard to work out why.