Tipi di dati ed eccezioni in Java
Jim White
Java Developer

Map definisce le operazioni su coppie chiave/valoreMapMap con comportamento simileHashMap
HashMap<Integer, String> map = new HashMap<Integer, String>();
Il costruttore parametrico/generico di HashMap richiede due tipi
Il primo tipo = tipo della chiave

Il secondo tipo = tipo del valore


java.util.HashMap.put(key,value) per aggiungere una coppia chiave/valore.remove(key) per rimuovere la coppia alla chiave indicata.get(key) per ottenere il valore alla chiaveimport java.util.HashMap
...
HashMap<Integer, String> map
= new HashMap<Integer, String>();
map.put(0, "Jim");
map.put(1, "James");
map.put(3, null);
map.put(4, "James");
map.remove(0);
System.out.println(map);
{1=James, 3=null, 4=James}
String nickname = map.get(1);
System.out.println(nickname);
James
java.util.Collections è una classe di supportostaticListaddAll(List list, Object a, b, ...)frequency(Collection c, Object o)Listreverse(List list)Listsort(List list)List con un altro oggettofill(List a, Object o)ArrayList<String> x = new ArrayList<String>(); Collections.addAll(x, "milk", "bread", "eggs", "milk"); System.out.println(x);int cnt = Collections.frequency(x, "milk"); System.out.println(cnt);Collections.reverse(x); System.out.println(x);Collections.sort(x); System.out.println(x);Collections.fill(x, "sugar"); System.out.println(x);
[milk, bread, eggs, milk]2[milk, eggs, bread, milk][bread, eggs, milk, milk][sugar, sugar, sugar, sugar]
int[]) in una ListList offre più funzioni (ricerca, ordinamento, ecc.)java.util.Arrays è un'altra classe di supportoListString[] arrayCountries = {"France", "Japan", "Brazil", "Egypt", "China"};
List<String> countries = Arrays.asList(arrayCountries);
System.out.println(countries);
[France, Japan, Brazil, Egypt, China]
Tipi di dati ed eccezioni in Java