| JAVA SPIEGAZIONE ARRAY E FUNZIONI |eng-ita

avatar

image.png

INTRODUZIONE

bentornati a tutti, oggi vi mostrerò in tutto e per tutto cos'è un array,la differenza tra i vari array e come si usano, accompagnando il tutto con degli esempi.

CHE COS'E' UN ARRAY?

Partiamo dalla definizione di array, un array non è altro che un contenitore, ma più appropriato chiamarlo armadio, poiché formato da più cassetti, che in informatica sono chiamati posizioni.
Quindi ogni array non è altro che un contenitore formato da posizioni che a loro volta possono contenere dati o oggetti...Andiamo a vederlo in modo più appropriato.

image.png

Possiamo rappresentare l'array in questo modo, come un contenitore formato da più posizioni, ogni posizione identificata da un numero che parte da 0,per utilizzare un array si parte obbligatoriamente da 0 e no può mai essere vuoto, possiamo utilizzare l'array quando abbiamo grandi quantità di dati da gestire.

DIFFERENZA ARRAY STATICI/DINAMICI

un array dinamico è molto diverso l'array statico, ognuno ha dei punti di forza e dei limiti, partiamo dalla definizione di array statico.
Per creare un array statico il comando è un pochino più lungo che per l'array dinamico poiché dobbiamo sapere alcuni dati:
-grandezza array;
-tipo di dato da inserire;

Purtroppo i limiti degli array statici stanno proprio qui, una volta che noi inseriamo la grande non può più essere modificata, e questo può essere un problema quando durante la scrittura del codice abbiamo qualche imprevisto, inoltre per l'uso dell'array dinamico, dobbiamo inserire ogni volta che vogliamo inserire qualcosa la posizione dell'array.
passiamo alla dimostrazione di un array statico.

image.png

per la dimostrazione ho proceduto alla creazione di un array che contiene numeri, come prima cosa ho messo il tipo di dato, quindi in questo caso int, poi dopo di che ho inserito la grandezza dell'array...in questo caso 10.
Mentre per l'inserimento dei numeri ho dovuto inserire manualmente la posizione ogni qual volta avevo qualcosa da aggiungere.

   int[] contentoreNumeri = new int[10];

Continuiamo con l'array dinamico, questo array è molto utile se siete esperti e volete accorciare le vostre tempistiche, poiché a differenza dell'array statico, non va inserita ne la grandezza dell'array ne la poszione...appunto il termine "DINAMICO",creerà tutto in automatico.

image.png
Ho proceduto con la creazione anche di un array dinamico, per spiegarvi passo passo le differenze...come già voi notate per la creazione di un array dinamico dobbiamo soltanto indicare la classe dell'array quindi limitiamo le tempistiche e rendiamo tutto più facile.
ogni volta che dobbiamo inserire un qualcosa dell'array basta inserire nome dell'array.add.

int[] contentoreNumeri = new int[10];

COME SI USA UN ARRAY

una volta creato un array...cosa ce ne facciamo?
la risposta è molto semplice, tutto quello che volete.
La comodità degli array sta proprio qui, potete aggiungere, modificare e rimuovere il loro contenuto.
Per far scorrere un array dovrete fare un array e farlo "scandire", una volta fatto vi basterà prendere il loro contenuto e modificarlo, o addirittura eliminarlo, con il seguente comando:

contentoreNumeri .remove(posizione);

SCANDIRE=far scorrere un array finché non troverà quello che vi serve.

COME SCANDIRE UN ARRAY

image.png

Qui sopra vi ho inserito come scorrere un array, per prima cosa inseriamo un for, all'interno inseriamo da quale numero partire quindi i=0,dopodiche per quante volte farlo quindi inseriamo la grandezza del nostro array con il nome del nostro array.size() e per ultimo il contatore da aggiornare,e per ultimo all'interno del nostro file eseguiamo l'istruzione che ci serve, IN QUESTO CASO HO FATTO SVUOTARE TUTTO L'ARRAY.

for(int i=0;i<contentoreNumeri.size();i++){



image.png

INTRODUCTION

welcome back everyone, today I am going to show you in all respects what an array is,the difference between the various arrays and how they are used, accompanying this with examples.

WHAT IS AN ARRAY?

Let us start with the definition of an array.An array is nothing more than a container, but more appropriate to call it a cabinet, since it consists of several drawers, which in computer science are called positions.
So each array is nothing but a container formed by positions, which in turn may contain data or objects...Let's look at it more appropriately.

image.png

We can represent the array in this way, as a container formed by several positions, each position identified by a number starting from 0,to use an array we must start from 0 and it can never be empty, we can use the array when we have large amounts of data to handle.

DIFFERENCE STATIC/DYNAMIC ARRAYS

a dynamic array is very different the static array, each has strengths and limitations, let's start with the definition of static array.
To create a static array the command is a little bit longer than for the dynamic array since we need to know some data:
-array size;
-type of data to be inserted;

Unfortunately, the limitations of static arrays lie right here, once we insert the size it can no longer be changed, and this can be a problem when during the writing of the code we have some unforeseen, also for the use of the dynamic array, we have to insert every time we want to insert something the position of the array.
Let's move on to the demonstration of a static array.

image.png

For the demonstration I proceeded to create an array that contains numbers, as first I put the data type, so in this case int, then after that I entered the size of the array...in this case 10.
While for entering the numbers I had to manually enter the position whenever I had something to add.

   int[] contentNumbers = new int[10];

Let's continue with the dynamic array, this array is very useful if you are experienced and want to shorten your timelines, because unlike the static array, neither the size of the array nor the position has to be entered...precisely the term "DYNAMIC",it will create everything automatically.

image.png
I proceeded with creating a dynamic array as well, to explain step by step the differences...as you already notice for creating a dynamic array we only have to indicate the class of the array so we limit the timing and make everything easier.
every time we need to insert something from the array just enter array name.add.

int[] contentNumbers = new int[10];

HOW TO USE AN ARRAY

once we have created an array...what do we do with it?
the answer is very simple, anything you want.
The convenience of arrays is right there, you can add, edit and remove their contents.
To run an array you will need to make an array and have it "scan," once done you can simply take their contents and modify, or even delete them, with the following command:

contentNumbers .remove(position);

SCANDER=scroll an array until it finds what you need.

HOW TO SCANDER AN ARRAY

image.png

Above I have entered you how to scroll an array, first we enter a for, inside we enter which number to start from so i=0,after that how many times to do it then we enter the size of our array with the name of our array.size() and lastly the counter to update,and lastly inside our file we execute the instruction we need, IN THIS CASE I HAVE MADE THE ENTIRE ARRAY UNSPEED.

for(int i=0;i<counterNumbers.size();i++){





0
0
0.000
4 comments
avatar

Congratulations @fraaaaa! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You published more than 20 posts.
Your next target is to reach 30 posts.
You distributed more than 50 upvotes.
Your next target is to reach 100 upvotes.
You received more than 500 upvotes.
Your next target is to reach 600 upvotes.
You made more than 100 comments.
Your next target is to reach 200 comments.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

HiveBuzz World Cup Contest - Recap of Day 9
Hive Power Up Day - December 1st 2022
HiveBuzz World Cup Contest - Check your ranking
Support the HiveBuzz project. Vote for our proposal!
0
0
0.000