1 / 8

Java base III: Array e Stringhe

Java base III: Array e Stringhe. Argomenti. Gli array Le stringhe. Obiettivi. Imparare a lavorare con gli array Imparare a lavorare con le stringhe. 0 1 2 3 4 5 6 7 8 9. 12. 43. 6. 83. 14. -57. 109. 12. 0. 6. Array o Vettore.

parry
Download Presentation

Java base III: Array e Stringhe

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java base III:Array e Stringhe

  2. Argomenti • Gli array • Le stringhe

  3. Obiettivi • Imparare a lavorare con gli array • Imparare a lavorare con le stringhe

  4. 0 1 2 3 4 5 6 7 8 9 12 43 6 83 14 -57 109 12 0 6 Array o Vettore Struttura dati complessa Si può immaginare un array come una sorta di casellario Indice 0…n Cella Ciascuna delle celle si comporta come una variabile tradizionale Tutte le celle sono variabili di uno stesso tipo Tipo base dell'array Si possono creare array contenenti qualsiasi tipo di dati Sono il primo esempio di oggetti la cui creazione deve essere esplicitamente gestita dal programmatore.

  5. Dichiarazione e uso degli array Dichiarazione int mioArray[]; Array di interi int[] mioArray; Inizializzazione mioArray = new int[10]; // Array di 10 elementi Dichiarazione e assegnazione rapida int[] mioArray = {1,2,7,9}; // Assegno i valori Recupero valore int t = mioArray[0]; // Assegna a t il valore // memorizzato nella posizione 0 Recupero lunghezza int lunghezza = mioArray.length;

  6. Array Multidimensionali Java non mette a disposizione array veramente multidimensionali Simulati come array di array Dichiarazione int matrice[][]; // Matrice di interi Allocazione matrice = new int[3][4]; // Matrice 3x4 Righe Colonne Assegnazione int matr[][] = { {1,2,3,4}, {5,6,7,8} }; Recupero elemento matrice[1][2]

  7. Lavorare con gli array multidimensionali Lunghezza di un array array.length Numero righe Numero colonne array[i].length Per lavorare con gli array multidimensionali Cicli Annidati for (int i = 0; i < m.length; i++){ for (int j = 0; j < m[i].length; j++){ m[i][j] = 1; } } Cosa fa questo blocco?

  8. Lavorare con le stringhe In Java, le stringhesonooggetti appartenenti alla classe String Sequenze di caratteri Memorizzate in apposite strutture Per concatenare stringhe diverse OPERATORE + Dichiarazione String stringa = “stringa”; Recuperare lunghezza stringa stringa.length(); Recuperare carattere i-esimo stringa.charAt(i); Estrarre sotto-stringa stringa.subString(inizio,fine); Valutare eguaglianza … stringa.equals(stringa2);

More Related