Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-16-2005, 03:15 PM   PM User | #1
Afrow UK
Regular Coder

 
Join Date: Dec 2002
Location: UK
Posts: 177
Thanks: 0
Thanked 2 Times in 2 Posts
Afrow UK is an unknown quantity at this point
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 :)~;
}
Afrow UK is offline   Reply With Quote
Old 02-16-2005, 04:00 PM   PM User | #2
shmoove
Regular Coder

 
Join Date: Dec 2003
Posts: 367
Thanks: 0
Thanked 0 Times in 0 Posts
shmoove is an unknown quantity at this point
You could store arrays in the ArrayList, or make an array of ArrayLists (depending on which dimension needs to be dynamic).

shmoove
shmoove is offline   Reply With Quote
Old 02-16-2005, 04:06 PM   PM User | #3
Afrow UK
Regular Coder

 
Join Date: Dec 2002
Location: UK
Posts: 177
Thanks: 0
Thanked 2 Times in 2 Posts
Afrow UK is an unknown quantity at this point
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 :)~;
}
Afrow UK is offline   Reply With Quote
Old 02-16-2005, 05:28 PM   PM User | #4
KeZZeR
Regular Coder

 
Join Date: Oct 2004
Location: England
Posts: 282
Thanks: 0
Thanked 0 Times in 0 Posts
KeZZeR is an unknown quantity at this point
Are you dynamically trying to initialise the array?
KeZZeR is offline   Reply With Quote
Old 02-16-2005, 05:52 PM   PM User | #5
cfc
Regular Coder

 
Join Date: Dec 2004
Location: Keswick, Ontario
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
cfc is an unknown quantity at this point
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 05:59 PM..
cfc is offline   Reply With Quote
Old 02-16-2005, 05:58 PM   PM User | #6
shmoove
Regular Coder

 
Join Date: Dec 2003
Posts: 367
Thanks: 0
Thanked 0 Times in 0 Posts
shmoove is an unknown quantity at this point
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
shmoove is offline   Reply With Quote
Old 02-16-2005, 06:09 PM   PM User | #7
cfc
Regular Coder

 
Join Date: Dec 2004
Location: Keswick, Ontario
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
cfc is an unknown quantity at this point
Thanks, I found something on it -- http://www-106.ibm.com/developerwork...-djc02113.html

It's pretty interesting
cfc is offline   Reply With Quote
Old 02-16-2005, 06:56 PM   PM User | #8
Afrow UK
Regular Coder

 
Join Date: Dec 2002
Location: UK
Posts: 177
Thanks: 0
Thanked 2 Times in 2 Posts
Afrow UK is an unknown quantity at this point
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 :)~;
}
Afrow UK is offline   Reply With Quote
Old 02-16-2005, 07:01 PM   PM User | #9
cfc
Regular Coder

 
Join Date: Dec 2004
Location: Keswick, Ontario
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
cfc is an unknown quantity at this point
Code:
if (x < 0) 
    x *= -1;
?

Last edited by cfc; 02-16-2005 at 07:17 PM..
cfc is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:20 PM.


Advertisement
Log in to turn off these ads.