Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Vector;
- public class Studente {
- public String nome;
- public String cognome;
- public int matricola;
- public Studente(String n, String c, int m) {
- nome = n;
- cognome = c;
- matricola = m;
- }
- public String toString() {
- return nome + " " + cognome + " " + matricola;
- }
- /*
- * Metodi importanti:
- *
- * size() per il ciclo for
- * add(Element) per aggiungere un elemento
- * remove(index) rimuovere elemento in un indice specifico
- * get(index)
- *
- *
- * */
- public static void main(String[] args) {
- System.out.println("-----");
- Studente s = new Studente("Dave","Gimo",1);
- Studente f = new Studente("Franco","Rossi",100);
- Studente m = new Studente("Mario","Bianchi",777);
- Vector<Studente> v = new Vector<Studente>();
- v.add(s);
- v.add(f);
- v.add(m);
- for (int i = 0; i < v.size(); i++ ) {
- if (v.get(i).nome == "Mario") {
- v.remove(i);
- }
- }
- //Ciclo di stampa
- for (int i = 0; i < v.size(); i++ ) {
- System.out.println(v.get(i).toString());
- // array[i]
- }
- System.out.println("-----");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement