Skip to content

Instantly share code, notes, and snippets.

@yusufcakmak
Created October 25, 2016 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yusufcakmak/bee27cf38db41065609f15725b0cfcc5 to your computer and use it in GitHub Desktop.
Save yusufcakmak/bee27cf38db41065609f15725b0cfcc5 to your computer and use it in GitHub Desktop.
public class JavaMap {
public static void main(String[] args) {
// Takımları temsil eden kısaltmaları ve isimleri ile Map oluşturuyoruz. Böylece her takım kısaltmasına karşılık takım ismi gelecek.
// put metotu ile ekleme yapıyoruz.
Map<String, String> teamMap = new HashMap<>();
teamMap.put("bjk","Besiktas");
teamMap.put("gs","Galatasaray");
teamMap.put("fb","Fenerbahce");
teamMap.put("ts",null);
// bjk anahtarına karşılık gelen değeri buluyoruz.
String teamValue = teamMap.get("bjk");
System.out.println("Key = bjk , Value = " + teamValue);
// oluşturduğumuz mapte kaç tane anahtar-değer ikilisi var bunu yazdırıyoruz.
System.out.println("teamMap size=" + teamMap.size());
// ikinci bir map oluşturup ilk map e eklediğimiz değerleri buna aktarıyoruz.
Map<String, String> teamMap1 = new HashMap<>();
teamMap1.putAll(teamMap);
System.out.println("teamMap1 mappings= " + teamMap1);
// map i eklediğimiz tüm ikililerden temizliyor ve yazdırıyoruz. Map boş olduğundan dolayı true değerini verecek.
teamMap.clear();
System.out.println("teamMap map is empty =" + teamMap.isEmpty());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment