1 / 23

Sets, Maps

Sets, Maps. Sets , Maps. Advanced Java. SoftUni Team. Technical Trainers. Software University. http://softuni.bg. Table of Contents. Sets – HashSet<E> , TreeSet<E>, LinkedHashSet<E> Maps – HashMap<K, V>, TreeMap<K, V>, LinkedHashMap<K, V>. Questions. sli.do #9286. 3 7. -3 5

jerryyoung
Download Presentation

Sets, Maps

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sets, Maps Sets, Maps AdvancedJava SoftUni Team Technical Trainers Software University http://softuni.bg

  2. Table of Contents Sets – HashSet<E>, TreeSet<E>, LinkedHashSet<E> Maps – HashMap<K,V>, TreeMap<K, V>, LinkedHashMap<K, V>

  3. Questions sli.do#9286

  4. 3 7 -3 5 46 Sets HashSet<E>, TreeSet<E> and LinkedHashSet<E>

  5. Sets in Java • A set keeps unique elements • Provides methods for adding/removing/searching elements • Offers very fast performance • HashSet<E> • The elements are randomly ordered • TreeSet<E> • The elements are ordered incrementally • LinkedHashSet<E> • The order of appearance is preserved

  6. HashSet<E> – add() • HashSet<String> Pesho Pesho • Hash Function Alice Gosho

  7. HashSet<E> – remove() • HashSet<String> • Hash Function Pesho Alice Alice Gosho

  8. TreeSet<E> – add() • TreeSet<String> Pesho Pesho Alice Gosho

  9. LinkedHashSet<E> – add() • LinkedHashSet<String> Pesho Pesho • Hash Function Alice Gosho

  10. HashSet<E>andTreeSet<E> Exercises in class

  11. иван гошо пешо 0845-346-356 2350-452-167 1255-377-131 Associative Arrays HashMap<Key, Value>

  12. Associative Arrays (Maps) • Traditional array • Associative array key value 0 1 2 3 4 key value • Associative arrays are arrays indexed by keys • Not by the numbers 0, 1, 2, … • Hold a set of pairs <key,value>

  13. HashMap<K, V> – add() • HashMap<String, String> Gosho Alice 0881-456-987 +359-899-55-592 Pesho 0881-123-987 • Hash Function • Key Value

  14. HashMap<K, V> – remove() • HashMap<String, String> Pesho Gosho 0881-456-987 • Hash Function Pesho • 0881-123-987 Alice +359-899-55-592 • Key Value

  15. TreeMap<K, V> – Example • TreeMap<String, String> Alice +359-899-55-592 Pesho 0881-123-987 • Key Value

  16. LinkedHashMap<K, V> – add() • HashMap<String, String> Gosho Alice 0881-456-987 +359-899-55-592 Pesho 0881-123-987 • Hash Function • Key Value

  17. Looping through dictionaries • Dictionary<string, string> Pesho Pesho 0881-123-987 0881-123-987 Gosho Gosho 0881-456-987 0881-456-987 Alice +359-899-55-592 Alice +359-899-55-592 • Key Value

  18. HashMap<K, V>, TreeMap<K, V>, LinkedHashMap<K, V> • Have method size() – the number of key-value pairs • keySet() – a set of unique keys • values() – a collection of all values • Basic operations – put(), remove(), clear() • Boolean methods: • containsKey() – checks if a key is present in the dictionary • containsValue()–checks if a value is present in the dictionary

  19. Associative Arrays Exercises in class

  20. Summary HashSet<E>, TreeSet<E> and LinkedHashSet<E> hold unique elements and are very fast HashMap<K,V>, TreeMap<K, V> andLinkedHashMap<K, V> are an associative arrays where a value is accessed by its key

  21. Sets, Maps https://softuni.bg/courses/java-fundamentals

  22. License This course (slides, examples, demos, videos, homework, etc.)is licensed under the "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International" license • Attribution: this work may contain portions from • "C# Fundamentals – Part 1" course by Telerik Academy under CC-BY-NC-SA license • "C# Fundamentals – Part 2" course by Telerik Academy under CC-BY-NC-SA license

  23. Free Trainings @ Software University • Software University Foundation – softuni.org • Software University – High-Quality Education, Profession and Job for Software Developers • softuni.bg • Software University @ Facebook • facebook.com/SoftwareUniversity • Software University @ YouTube • youtube.com/SoftwareUniversity • Software University Forums – forum.softuni.bg

More Related