انتقل إلى المحتوى
أمين أبوزيد
BEG-030

المجموعات (Collections)

  • 9 درس
  • 99 دقيقة قراءة
  • 5 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • List
  • Set
  • Map
  • Queue
  • ArrayList
  • LinkedList
  • HashSet
  • HashMap
  • TreeMap

تعلّم أولًا

99 دقيقة قراءة · 5 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Use List, Set, Map, and Queue and choose the right one for a task.
  2. Choose between ArrayList/LinkedList, HashSet/TreeSet, HashMap/TreeMap based on ordering and access needs.
  3. Iterate safely, including removing elements during iteration.
  4. Declare variables by interface type (List<String> x = new ArrayList<>()).

الدروس

  1. 01ما بعد المصفوفات: إطار المجموعات (Collections Framework)11 د قراءة
  2. 02القوائم (Lists)12 د قراءة
  3. 03المجموعات (Sets)10 د قراءة
  4. 04الخرائط (Maps)12 د قراءة
  5. 05الطوابير (Queues) والطوابير ثنائية الطرف (deques)10 د قراءة
  6. 06اختيار المجموعة: مخطط القرار11 د قراءة
  7. 07التكرار وConcurrentModificationException11 د قراءة
  8. 08عرض عملي: تكرار الكلمات باستخدام Map10 د قراءة
  9. 09عرض عملي: المجموعة الخاطئة، بالقياس12 د قراءة

المختبر والتمارين

Lab

BEG-030-LAB1 · Word frequency

Outcomes: 1–4 · Time: ~3 h Read a paragraph (a file or a text block). Count word frequencies with a Map, list the unique words alphabetically, and show the top 10 by count. Write one line explaining each collection you chose. Acceptance: correct counts; justified collection choices.

Exercises (assessment: six exercises plus a collection-choice quiz)

IDOutcomeTask
BEG-030-EX011Create a List<String> of five names; add, remove one by value, and print its size and the second element.
BEG-030-EX021Remove duplicates from a list of numbers using a Set; print the result in the original order.
BEG-030-EX032For each need, pick the class: sorted unique names; fast key lookup; insertion-ordered unique tags; frequent insert at the front.
BEG-030-EX041Use a Queue to simulate three customers being served in arrival order.
BEG-030-EX053Remove all negative numbers from a list, first showing the failing for-each version, then a safe fix.
BEG-030-EX064Rewrite ArrayList<String> x = new ArrayList<String>(); using interface type and diamond; explain the benefit.
أظهر الحلول
  • EX01 List<String> l = new ArrayList<>(List.of("a","b","c","d","e")); l.add("f"); l.remove("c"); l.size(); l.get(1);
  • EX02 new ArrayList<>(new LinkedHashSet<>(numbers)) keeps first-seen order.
  • EX03 TreeSet; HashMap; LinkedHashSet; ArrayDeque/LinkedList (use addFirst).
  • EX04 Queue<String> q = new ArrayDeque<>(); q.offer(...) three times, then while (!q.isEmpty()) System.out.println(q.poll());.
  • EX05 For-each with remove throws ConcurrentModificationException; fix: list.removeIf(n -> n < 0);.
  • EX06 List<String> x = new ArrayList<>(); The variable type is the interface, so the implementation can change in one place.
  • The collection-choice quiz is اختبار الوحدة; it also covers outcome 2.

الاختبار

Outcomes: O1 List/Set/Map/Queue · O2 choosing implementations · O3 safe iteration · O4 interface types.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1Which collection does not allow duplicate elements?O1
  2. 2Which stores key-value pairs?O1
  3. 3A first-in, first-out waiting line is a:O1
  4. 4You want unique names kept sorted. Use:O2
  5. 5Default general-purpose list:O2
  6. 6Fast lookup of an order by its id:O2
  7. 7Which map keeps keys in sorted order?O2
  8. 8Removing from a list inside a for-each usually causes:O3
  9. 9A simple safe way to remove matching elements:O3
  10. 10Which declaration is best style?O4

الجزء العملي

Six exercises BEG-030-EX01 to EX06 plus the lab. Pass: at least five exercises correct, quiz 8/10, and every collection in the lab justified.

أخطاء شائعة

List where a Set or Map is needed (O(n) lookups); modifying a list while iterating.

التقييم

6 exercises plus a collection-choice quiz.

الصلة بالمسار الوظيفي

Used in every Java program; internals in BEG-040/041.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.