Simple question /Solved/

Okay, I'm not much into java programming and I've just encountered a problem… how can I create an array of rays?

thats really quite basic.



Ray[] rays = new Ray[42];



Maybe you should get yourself a good Java Programming book from Amazon?

Sigh, thanks!

Been trying to use this code as sample (it's from sun's page) but changed ints into Ray:


The following program, ArrayDemo, creates an array of integers, puts some values in it, and prints each value to standard output.

    class ArrayDemo {
         public static void main(String[] args) {
              int[] anArray;              // declares an array of integers

              anArray = new int[10];      // allocates memory for 10 integers




which ended up with errors.
dhdd said:

Maybe you should get yourself a good Java Programming book from Amazon?

Probably. And if reading that book causes you to not use arrays at all, it was a good one ;)
irrisor said:

Probably. And if reading that book causes you to not use arrays at all, it was a good one ;)


I like arrays and i know my way around Java quite well. You sir, are an Arraycist!  :lol:

PS: jME makes extensive use of the ArrayList. We dont see the array but its there anyway  ;)

hehe



I surely didn't mean you wouldn't use them under the hood, but I think you know that.

irrisor said:

but I think you know that.


of course  ;)

Making fun of lil noob me are we? :confused:

Seriously, no.  :wink:

Hey Morq,



If you don't feel easy with the Collection/List interface and/or Java, here's a couple snippets for you, showing how to make use of ArrayList in your particular case:


   public java.util.List<Ray> makeRayArray()   {
      java.util.List<Ray> rayList = new java.util.ArrayList<Ray>();
      
      return rayList;
   }
   
   public void addRay(Ray r, java.util.List<Ray> container) {
      container.add(r);
   }
   
   public void testRay() {
      java.util.List<Ray> listOfRays = makeRayArray();
      
      Ray r1 = new Ray();
      
      addRay(r1, listOfRays);
      addRay(new Ray(), listOfRays);

      for (Ray r : listOfRays){
         System.out.println("this ray has for origin: " + r.getOrigin());
      }
   }
      



Hope it gives some pointers...

^.-

Sorry for the spamming, but I'm XD right now.


You sir, are an Arraycist!


We dont see the array but its there anyway


This entries could make it into my all-time favorites. You made my day, thanks. 

@hobstad: Thanks :slight_smile:



@Rest: Thanks to you too!

desertrunner said:

This entries could make it into my all-time favorites. You made my day, thanks. 


my pleasure  ;)