6 Replies Latest reply on Apr 28, 2009 5:32 AM by 699554

    Help with Array of Arrays

    807588
      import java.util.Arrays;
      import java.util.Date;
      import java.util.List;
      
      public class StockDay
      {
          private String[] stockDayData;
          List stockDays = new ArrayList();
          
          public StockDay(String stockData)
          {
              stockDayData = new String[6];
              String[] stockDayData= stockData.split(",");
              stockDays.add(stockDayData[]);
              
      
          }
      }
      I have an outside class calling this class with a string of data separated by commas. I am trying to separate the data so that each time the method is called, each piece of the data (6 total) is put into an array list. Then that array list is put into an array list of arrays. I am sorry if I have not made this clear, I will try again. I want an array of arrays, and the interior arrays will contain 6 pieces of information each from the string that is given to the method, and each separated by commas.

      Any help is much appreciated. I am also curious how I can accesses one piece of the data at a time, this is what I am thinking for this:
      data = arraylist1[#].arraylist2[#]
      this would set data equal to whatever is in arraylist2[#]

      Thank you very much.
        • 1. Re: Help with Array of Arrays
          796440
          So what specific problems are you having? Also, be clear on your terminology. Do you want arrays, ArrayLists, or a combination? Note that there is no such thing as an "array list."
          • 2. Re: Help with Array of Arrays
            807588
            I am going to need to be able to sort the array that contains the other arrays, so I guess it would be best to use a fixed Array[] to hold the 6 pieces of data, and the other one depends on how I can sort them. I am going to need to be able to sort the array or arrays by highest to lowest according to one of the pieces of data. I think it is best to use an ArrayList() for that array. My question is, am I doing this correctly with the code above? and I am also getting an error when I try to compile the code above. I am looking for help with both what I am doing, and why mine wont even compile to test it.
            • 3. Re: Help with Array of Arrays
              796440
              ActingRude wrote:
              I am going to need to be able to sort the array that contains the other arrays, so I guess it would be best to use a fixed Array[]
              What is an Array[]? You mean array? Or array of arrays?
              My question is, am I doing this correctly with the code above? and I am also getting an error when I try to compile the code above.
              Sorry, I still don't really understand what you're trying to do. But when you test it, if you get the results you expected, then it's correct, at least for your test data. If not, it's not.
              • 4. Re: Help with Array of Arrays
                807588
                I meant just a simple Array I guess... like I am using above? I was under the impression that the biggest syntax difference between an array(fixed number of items) and an ArrayList(unfixed number of items) was the use of the [] and () I thought that I was being more clear by doing that but apparently I was not... I can not test it because I can not get it to
                when I attempt to run the class I get:
                UnsupportedOperationException:
                null (in java.util.AbstractList)
                I have no idea what is causing this, I can only assume that I am doing something wrong...


                Never mind, I have messed up the class trying to do this, it is now beyond repair... time to start over...

                Edited by: ActingRude on Apr 27, 2009 8:18 PM
                • 5. Re: Help with Array of Arrays
                  796440
                  ActingRude wrote:
                  I meant just a simple Array I guess.
                  Note the difference between Array and array. Class names start with uppercase in java. There is a class called Array, but it's just a utility class, and isn't part of arrays.
                  .. like I am using above? I was under the impression that the biggest syntax difference between an array(fixed number of items) and an ArrayList(unfixed number of items) was the use of the [] and ()
                  That's one of many syntactical differences, yes, but the main difference is not in the syntax. arrays are part of the Java language, have special handling because of that, and are faster and smaller than ArrayLists. ArrayList is part of the API, and didn't exist until Java 1.2 (about 5-6 years into Java's life, I think), and is built on top of an array.
                  UnsupportedOperationException:
                  null (in java.util.AbstractList)
                  I have no idea what is causing this, I can only assume that I am doing something wrong...
                  It looks like you're tyring to add null to an ArrayList and it doesn't like it. I thought ArrayList accepted null elements, but I could be wrong. Paste in the exact line that's causing it, and any declarations necessary to clarify any variables used on that line.
                  • 6. Re: Help with Array of Arrays
                    699554
                    ActingRude wrote:
                    UnsupportedOperationException:
                    null (in java.util.AbstractList)
                    Read the API ???
                    stockDays.add(stockDayData[]);
                    Something smells fishy

                    Mel