Download presentation
Presentation is loading. Please wait.
Published byMaude Ward Modified over 8 years ago
1
Collection 105 Yola
2
To store data in RAM Variables (name all the types with their length) Arrays (one, two or more) Collections and Maps
3
Collection Queue - a collection of values awaiting a processing. FIFO List – an ordered collection Set – a collection without duplicates Map – use associative keys. Search by its value but not the index Two interfaces for the dynamic data structures
4
How to use ArrayList import java.util.ArrayList; import java.util.Scanner; public class ArrLstExt { public static void main(String[] args) { ArrayList city = new ArrayList (); String name=""; Scanner a = new Scanner(System.in); while(!name.equals("stop")){ System.out.println("Input a name:"); name = a.next(); city.add(name); } city.set(1, "first city"); // to modify an element; }
5
Assignment 1 1.Implement search on the array list 2.Implement sort (find a method) 3.Implement shuffle (find a method) 4.Find min and max (find a method) 5.Swap two elements of an ArrayList
6
How to use queue import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class QueueEx { public static void main(String[] args) { Queue city = new LinkedList(); String name=""; Scanner a = new Scanner(System.in); while(!name.equals("stop")){ System.out.println("Input a name:"); name = a.next(); city.add(name); } System.out.println(city.poll()); // to remove the first item System.out.println(city.poll()); // to see without removing }
7
Assignment Input several values to queue Input several values to another List Synchronize queue to the List (leave only elements that present in the List)
8
How to use Set import java.util.HashSet; import java.util.Set; public class SetEx { public static void main(String[] args) { Set city = new HashSet(); Set city1 = new HashSet(); city.add("a"); city.add("b"); city.add("c"); city1.add("c"); city.add("d"); System.out.println(city.contains("a")); System.out.println(city.hashCode()==city1.hashCode()); city.retainAll(city1);// intersection of sets }}
9
How to use Map? This is HOME ASSIGNMENT!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.