Changes

Jump to navigation Jump to search
935 bytes added ,  10:14, 20 April 2022
m
Line 3: Line 3:  
===With apt===
 
===With apt===
 
  <nowiki>sudo apt-add-repository ppa:webupd8team/java
 
  <nowiki>sudo apt-add-repository ppa:webupd8team/java
                        sudo apt-get update
+
                          sudo apt-get update
                        sudo apt-get install oracle-java8-installer</nowiki>
+
                          sudo apt-get install oracle-java8-installer</nowiki>
    
Also ensure your JAVA_HOME variable has been set to:
 
Also ensure your JAVA_HOME variable has been set to:
Line 390: Line 390:  
</syntaxhighlight>
 
</syntaxhighlight>
   −
=== Tree (Reduces cost of search, insert and delete) ===
+
===Tree (Reduces cost of search, insert and delete)===
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
 
TreeSet<Integer> numbers = new TreeSet<>(Set.of(65, 54, 34, 12, 99));
 
TreeSet<Integer> numbers = new TreeSet<>(Set.of(65, 54, 34, 12, 99));
Line 401: Line 401:  
</syntaxhighlight>
 
</syntaxhighlight>
   −
=== Queue ===
+
===Queue===
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
 
Queue <String> queue = new PriorityQueue<>();
 
Queue <String> queue = new PriorityQueue<>();
Line 429: Line 429:  
     }
 
     }
 
}
 
}
 +
</syntaxhighlight>
 +
 +
=== Map ===
 +
Key - Value Pair
 +
 +
HashMap --> Not syncronized
 +
 +
HashTable -> synchronized (thread safe)
 +
 +
LinkedHashMap -> Insertion order is mainained, slower deletion and insertion, faster iteration
 +
 +
TreeMap -> Data stored in sorted order<syntaxhighlight lang="java">
 +
Map<String, Integer> map = Map.of("A", 3, "B", 5, "Z", 10);
 +
map.get("Z");
 +
map.size();
 +
map.isEmpty();
 +
map.containsKey("A");
 +
map.cointainsValue(4);
 +
map.keySet();
 +
map.values();
 +
 +
Map<String, Integer> hashmap = new HashMap(map);
 +
hashmap.put("F", 5);
 +
 +
</syntaxhighlight><syntaxhighlight lang="java">
 +
HashMap<String, Integer> hashmap = new HashMap<>();
 +
hashmap.put("Z", 5);
 +
hashmap.put("A", 7);
 +
 +
//keeps insertion order
 +
LinkedhashMap<String, Integer> linkedHashMap = new LinkkedHashMap<>();
 +
linkedHashMap.put("F", 25);
 +
linkedHashMap.put("A", 15);
 +
 +
// sorts on keys
 +
TreeMap<String, Integer> treemap = new TreeMap<>();
 +
treemap.put("Z", 5);
 +
treemap.put("A", 7);
 +
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Navigation menu