المجموعات (Collections)
في هذه الصفحة 8 موضوعات
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
نظرة عامة
الموضوعات
- List
- Set
- Map
- Queue
- ArrayList
- LinkedList
- HashSet
- HashMap
- TreeMap
تعلّم أولًا
99 دقيقة قراءة · 5 ساعة تدريب (تقدير)
مخرجات التعلم
- Use
List,Set,Map, andQueueand choose the right one for a task. - Choose between
ArrayList/LinkedList,HashSet/TreeSet,HashMap/TreeMapbased on ordering and access needs. - Iterate safely, including removing elements during iteration.
- Declare variables by interface type (
List<String> x = new ArrayList<>()).
الدروس
- 01ما بعد المصفوفات: إطار المجموعات (Collections Framework)11 د قراءة
- 02القوائم (Lists)12 د قراءة
- 03المجموعات (Sets)10 د قراءة
- 04الخرائط (Maps)12 د قراءة
- 05الطوابير (Queues) والطوابير ثنائية الطرف (deques)10 د قراءة
- 06اختيار المجموعة: مخطط القرار11 د قراءة
- 07التكرار وConcurrentModificationException11 د قراءة
- 08عرض عملي: تكرار الكلمات باستخدام Map10 د قراءة
- 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)
| ID | Outcome | Task |
|---|---|---|
| BEG-030-EX01 | 1 | Create a List<String> of five names; add, remove one by value, and print its size and the second element. |
| BEG-030-EX02 | 1 | Remove duplicates from a list of numbers using a Set; print the result in the original order. |
| BEG-030-EX03 | 2 | For each need, pick the class: sorted unique names; fast key lookup; insertion-ordered unique tags; frequent insert at the front. |
| BEG-030-EX04 | 1 | Use a Queue to simulate three customers being served in arrival order. |
| BEG-030-EX05 | 3 | Remove all negative numbers from a list, first showing the failing for-each version, then a safe fix. |
| BEG-030-EX06 | 4 | Rewrite 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(useaddFirst). - EX04
Queue<String> q = new ArrayDeque<>(); q.offer(...)three times, thenwhile (!q.isEmpty()) System.out.println(q.poll());. - EX05 For-each with
removethrowsConcurrentModificationException; 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.
اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.
الجزء العملي
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.