Typy danych i wyjątki w Javie
Jim White
Java Developer

Map definiuje operacje na parach klucz–wartośćMapMap o podobnym zachowaniuMap jest HashMap
HashMap<Integer, String> map = new HashMap<Integer, String>();
Parametryzowany konstruktor HashMap wymaga dwóch typów
Pierwszy typ = typ klucza

Drugi typ = typ wartości


java.util.HashMap.put(key,value) – dodaje parę klucz/wartość do tablicy.remove(key) – usuwa parę klucz/wartość dla podanego klucza.get(key) – pobiera wartość z tablicy dla podanego kluczaimport 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 to klasa pomocniczastaticListaddAll(List list, Object a, b, ...)frequency(Collection c, Object o)Listreverse(List list)Listsort(List list)List innym obiektemfill(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[]) na ListList oferuje większe możliwości (wyszukiwanie, sortowanie itp.)java.util.Arrays to kolejna klasa pomocniczaListString[] arrayCountries = {"France", "Japan", "Brazil", "Egypt", "China"};
List<String> countries = Arrays.asList(arrayCountries);
System.out.println(countries);
[France, Japan, Brazil, Egypt, China]
Typy danych i wyjątki w Javie