CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    1

    List<float> = missing token?

    Hi I just started up java recently, and I've been struggling on how to make a list of floating point numbers. The error I get is "dimensions expected after this token" but all examples on the web don't really point to a reason as to what or how i should approach this. THanks.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,405

    Re: List<float> = missing token?

    Quote Originally Posted by taiL View Post
    Hi I just started up java recently, and I've been struggling on how to make a list of floating point numbers. The error I get is "dimensions expected after this token" but all examples on the web don't really point to a reason as to what or how i should approach this. THanks.
    It's not quite clear what your problem is. But here are a few pointers.

    First, you cannot store primitives in Java collections. What you need to do is to store the corresponding wrapper class. The corresponding wrapper to a float is a Float.

    Second, List is an interface and not a concrete class. You can declare a variable of type List but you need to create and assign a concrete class object to it, like

    List<Float> l = new ArrayList<Float>();

    or

    List<Float> l = new LinkedList<Float>();

    ArrayList and LinkedList both implement the List interface (but have different properties).

    Now you can start adding Float objects to the List<Float> you've created. In fact you can even add float primitives thanks to a Java feature called autoboxing. Autoboxing makes sure a primitive (like a float) gets converted to its corresponding wrapper class (like a Float) and back agan when it needs to be.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured