Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    177
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Dynamic and multi-dimensional array in Java?

    I've tried an ArrayList, and it's dynamic, but I can't make it multi-dimensional!

    Is it possible to have an array of 2 dimensions that has the first dimension dynamic?
    e.g. [x][0], [x][1] etc

    -Stu
    if ($ENV{'QUERY_STRING'} eq "Afrow UK") {
    print "$ENV{'QUERY_STRING'} rocks!";
    } else {
    print qq~$ENV{'QUERY_STRING'} sucks :)~;
    }

  • #2
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could store arrays in the ArrayList, or make an array of ArrayLists (depending on which dimension needs to be dynamic).

    shmoove

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    177
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Yeh I would if I knew how...

    -Stu
    if ($ENV{'QUERY_STRING'} eq "Afrow UK") {
    print "$ENV{'QUERY_STRING'} rocks!";
    } else {
    print qq~$ENV{'QUERY_STRING'} sucks :)~;
    }

  • #4
    Regular Coder
    Join Date
    Oct 2004
    Location
    England
    Posts
    282
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you dynamically trying to initialise the array?

  • #5
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When it comes to specific class use, the API specs are your best friend. Java is extremely well-documented, given that you know what you're looking for. I linked to the Java 1.5 documentation, but you can replace the 1.5.0 in the url with whatever version you're using (ie. 1.4.2).

    What's with all the <E> and <T> stuff in the Collections framework now? I couldn't help but notice that ArrayList.get(int index) now returns something with a class of E and ArrayList.add() takes an argument of class E. Also, ArrayList.toArray() returns an array of objects with class T
    Last edited by cfc; 02-16-2005 at 06:59 PM.

  • #6
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cfc
    When it comes to specific class use, the
    What's with all the <E> and <T> stuff in the Collections framework now?
    Generics (like templates in C++).

    shmoove

  • #7
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I found something on it -- http://www-106.ibm.com/developerwork...-djc02113.html

    It's pretty interesting

  • #8
    Regular Coder
    Join Date
    Dec 2002
    Location
    UK
    Posts
    177
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Thanks all.
    Here is another question. What is the easiest or quickest way to convert a negative integer to a positive integer?

    -Stu
    if ($ENV{'QUERY_STRING'} eq "Afrow UK") {
    print "$ENV{'QUERY_STRING'} rocks!";
    } else {
    print qq~$ENV{'QUERY_STRING'} sucks :)~;
    }

  • #9
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    if (x < 0) 
        x *= -1;
    ?
    Last edited by cfc; 02-16-2005 at 08:17 PM.


  •  

    Posting Permissions

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