I'm looking to create an Arraylist of double arrays. Is there any way I can fill it without declaring an array each time? i.e.:
This, of course, does not work, but just trying to give you an idea of what I'm looking for. The other option would be if I could fill a single array and keep adding those, but as far as I can see, Java doesn't allow you to fill an entire array in one line of code unless you are initializing it in the same line.
Does anyone have any suggestions? About the only thing that seems plausible to me now would be to create a new array each time, which seems counter-intuitive.
Terry, that definitely works but I need to add multiple double arrays to my arrayList, and to do that I'd have to create a new array each time, possible but not ideal.
Bear, I'd prefer to do that but as far as I can tell, items can only be added one at a time, which would be a lot of extra lines of code, or through Arrays.asList, which again requires a new declaration each time. If I'm wrong though, please let me know, thanks! I'm trying to make a polynomial function; each double array contains the coefficients for a polynomial.
Well, first of all if you want to add ten arrays to your list then you do actually have to create ten arrays. I don't know why you think that's "not ideal". And it is possible to add them all at once if you like (there's an addAll(Collection) method you could use), but you still have to create them all first. I guess I'm not quite getting what your problem is really.
Joined: Sep 23, 2009
I just feel like it's a bit of a waste to create 50ish arrays for the sole cause of feeding them into an arrayList. I'll do it if I have to, but I was just wondering if there was an easier way without initializing a new array each time. Thanks!
You'll probably hear this a lot before you stop being a programmer (unlike some of us who are stuck in the rut ).
And if you don't, you haven't talked to the right people:
1. NEVER guess. Never, ever, ever, ever...well, unless you're programming the next Deep Blue.
2. "More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason — including blind stupidity." — W.A. Wulf
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here