View Full Version : [java] vector e matrici
Miky Mouse
16-12-2007, 07:59
vorrei sapere se esiste una struttura simile ai vector ma che sia una matrice di oggetti e non un vettore... o se altrimenti se devo usare un vector di vector (si può fare no?)
grazie :)
A Vector is an historical collection class that acts like a growable array, but can store heterogeneous data elements. With the Java 2 SDK, version 2, the Vector class has been retrofitted into the Collections Framework hierarchy to implement the List interface. However, if you are using the new framework, you should use ArrayList, instead.
http://java.sun.com/developer/onlineTraining/collections/Collection.html#VectorAndStackClasses
Quindi diciamo che al massimo la scelta si un ArrayList di ArrayList ;) A meno che tu non sia in ambiente multithreading (l'ArrayList non è synchronized).
La scelta migliore imho è quella di astrarre la struttura dati che usi (a questo punto un ArrayList di ArrayList) e di creare un classe Matrix che la contiene.
In alternativa puoi usare qualcosa di già pronto come questa, sempre che tu voglia fare elaborazione numerica: http://math.nist.gov/javanumerics/jama/
E' la prima che ho trovato, quindi non ti limitare a quella.
Miky Mouse
16-12-2007, 08:35
A Vector is an historical collection class that acts like a growable array, but can store heterogeneous data elements. With the Java 2 SDK, version 2, the Vector class has been retrofitted into the Collections Framework hierarchy to implement the List interface. However, if you are using the new framework, you should use ArrayList, instead.
http://java.sun.com/developer/onlineTraining/collections/Collection.html#VectorAndStackClasses
Quindi diciamo che al massimo la scelta si un ArrayList di ArrayList ;) A meno che tu non sia in ambiente multithreading (l'ArrayList non è synchronized).
La scelta migliore imho è quella di astrarre la struttura dati che usi (a questo punto un ArrayList di ArrayList) e di creare un classe Matrix che la contiene.
In alternativa puoi usare qualcosa di già pronto come questa, sempre che tu voglia fare elaborazione numerica: http://math.nist.gov/javanumerics/jama/
E' la prima che ho trovato, quindi non ti limitare a quella.
no purtroppo devo usare cose il più standard possibile per tenermi fuori dai guai :D
però è ottima l'idea di creare un'altra classe, anche se non l'ho capita in pieno, praticamente diventerebbe trasparente a chi chiama il fatto che dentro a matrix ci siano arraylist di arraylist perche gestirei tutto come una matrice matrix giusto? scusate sono alle primissime armi :D
però è ottima l'idea di creare un'altra classe, anche se non l'ho capita in pieno, praticamente diventerebbe trasparente a chi chiama il fatto che dentro a matrix ci siano arraylist di arraylist perche gestirei tutto come una matrice matrix giusto? scusate sono alle primissime armi :D
Sì.
Ti crei una classe Matrix con i metodi:
void set(int row, int column, int double)
double get(int row, int column)
e magari altri operatori (non ho ancora capito se devi farci operazioni matematiche con queste matrici):
Matrix multiply(Matrix m);
Matrix multiply(double d);
Matrix sum(Matrix m);
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.