12 Replies Latest reply: Dec 4, 2007 10:17 AM by 807600 RSS

    2D arrayList

    807600
      Hi,

      How can I create a 2D ArrayList (or anything else similar to that) if I don't know the number of rows and lines??

      Thanx!
        • 1. Re: 2D arrayList
          807600
          You could create a List of Lists where each Item in the initial List represents one row of data. This would be very similar to how multi-dimensional arrays are handled in Java.

          But please tell us why you need such a thing. There might be better data structures for your requirement.
          • 2. Re: 2D arrayList
            807600
            I have to store all the elements of an xml file which includes datasource and parameter tags like the following:
                <datasource name1="asas" name2="15:34" name3="5G" name4="mp3">
                    <parameter name="language" value="en"/>
            <parameter name="language" value="en"/>
            There are a lot of datasource elements and each datasource has a lot of parameters. I don't know the number of any of those.
            • 3. Re: 2D arrayList
              807600
              I have to store all the elements of an xml file which includes datasource and parameter tags like the following:
                  <datasource name1="asas" name2="15:34" name3="5G" name4="mp3">
                      <parameter name="language" value="en"/>
                      <parameter name="country" value="uk"/>
              There are a lot of datasource elements and each datasource includes a lot of parameters. I don't know the number of any of those.

              I thought 2D arraylist is ok.. but from your previous answer I am a bit confused!

              Is there any more clear way?
              • 4. Re: 2D arrayList
                807600
                How about creating a class that allows storage of each datasource and related data and then have an arraylist of objects of this class?

                Or a standard database?
                • 5. Re: 2D arrayList
                  807600
                  I'll try to make a new class. If I have any problems I'll post back!

                  Thanx for the help..
                  • 6. Re: 2D arrayList
                    807600
                    I know little about this subject, but I believe that there libraries out there that allow XML (with a schema, I believe) to define their own classes so that all of this class information is in the XML / XSD and outside of the code that the reads the XML. But again, I'm speaking out of ignorance (hopefully soon to be corrected).
                    • 7. Re: 2D arrayList
                      807600
                      petes1234 wrote:
                      How about creating a class that allows storage of each datasource and related data and then have an arraylist of objects of this class?

                      Or a standard database?
                      Indeed. The original desire for a list of lists was just a case of object denial.
                      • 8. Re: 2D arrayList
                        807600
                        petes1234 wrote:
                        I know little about this subject, but I believe that there libraries out there that allow XML (with a schema, I believe) to define their own classes so that all of this class information is in the XML / XSD and outside of the code that the reads the XML. But again, I'm speaking out of ignorance (hopefully soon to be corrected).
                        You may be thinking of XMLBeans

                        http://xmlbeans.apache.org/

                        or JAXB.

                        I've used XMLBeans and it's slicker than a greased pig.
                        • 9. Re: 2D arrayList
                          807600
                          Hippolyte wrote:
                          You may be thinking of XMLBeans
                          or JAXB.
                          It was JAXB.
                          I've used XMLBeans and it's slicker than a greased pig.
                          Mind if I tap your brain and hijack a thread? Would you recommend learning XMLBeans over JAXB?
                          What if you need just a plain non-fancy XML DOM parser? Would you just go with the standard Java libraries or use something else?
                          • 10. Re: 2D arrayList
                            807600
                            petes1234 wrote:
                            Hippolyte wrote:
                            You may be thinking of XMLBeans
                            or JAXB.
                            It was JAXB.
                            I've used XMLBeans and it's slicker than a greased pig.
                            Mind if I tap your brain and hijack a thread? Would you recommend learning XMLBeans over JAXB?
                            What if you need just a plain non-fancy XML DOM parser? Would you just go with the standard Java libraries or use something else?
                            I joined the project that was using XMLBeans after the decision to use it over JAXB was made. I was told that XMLBeans was lighter -- it creates a facade over a DOM tree rather than translating the DOM object into something else. The project was dealing with some large XML objects and complex schemas, too.

                            Remember that both these methods (XMLBeans/JAXB) require you to first compile an XML Schema into Java classes, so keep that in mind.

                            In the standard Java library, if I didn't need to generate Schema-specific objects, I would first consider JDOM -- or is there a newer alternative to JDOM?
                            • 11. Re: 2D arrayList
                              807600
                              Thanks for the useful info!
                              In the standard Java library, if I didn't need to generate Schema-specific objects, I would first consider JDOM -- or is there a newer alternative to JDOM?
                              I don't know. Where does Xerxes fit in here? Or does it?
                              • 12. Re: 2D arrayList
                                807600
                                petes1234 wrote:
                                Thanks for the useful info!
                                In the standard Java library, if I didn't need to generate Schema-specific objects, I would first consider JDOM -- or is there a newer alternative to JDOM?
                                I don't know. Where does Xerxes fit in here? Or does it?
                                Xerces is an implementation of an XML parser, so it used, often under the hood, when using SAX or DOM APIs.