is it possible to create a dynamic number of columns in arrays?
I'm new to java and was wondering how you would suggest I solve this problem.
Basically I have database with a ton of portfolio date such as:
portfolio date ticker size price
1 2011-06-07 agf.b 0 20
1 2011-06-07 ibm 0 5
1 2011-06-07 gs 0 10
1 2011-06-07 msft 0 2
1 2011-06-07 c 30 4
2 2011-06-07 agf.b 0 20
2 2011-06-07 ibm 0 5
2 2011-06-07 gs 0 10
2 2011-06-07 msft 2 2
2 2011-06-07 c 29 4
3 2011-06-07 agf.b 0 20
3 2011-06-07 ibm 0 5
3 2011-06-07 gs 0 10
3 2011-06-07 msft 4 2
3 2011-06-07 c 28 4
I want to put all this into an array for each portfolio of stocks(everyday the database creates several million portfolios.
My problem is, I know the number of portfolios in the system(via sql command), and I create an array with a fixed size based on that, but I don't know the number of stocks within the portfolios(as some are zero). I am testing with 4 stocks but in a live situation it could have any number of stocks.
To give some context, my ultimate goal is to get two arrays, one of today's portfolios and one of yesterdays(studying the relationship between portfolios and not individual stocks) and analyze each one against the others in the list(and then assign certain fitness scores to each one).
I'm not sure how to approach this problem, but I suspect the first thing to do i开发者_运维百科s to get both in an array. Any help would be appreciated.
Thanks!
ArrayList is a variable-size container.
Resizable-array implementation of the List interface.
A tutorial on the List interface (part of the Collections Framework) can be found here:
- http://download.oracle.com/javase/tutorial/collections/interfaces/list.html
You could use java.util.List
.
You need a ArrayList Collection to do this.
Resizable-array implementation of the List interface. Implements all optional list operations, and permits all elements, including null. In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list. (This class is roughly equivalent to Vector, except that it is unsynchronized.)
Look into the ArrayList class. It is backed by an array and grows dynamically as you add data to it. Operations are carried out in amortized constant time.
精彩评论