Quick Intro to Java Collections

669
-1

Published on

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
669
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
26
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Quick Intro to Java Collections

  1. 1. Quick  Intro  to  Java  Collec2ons   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  2. 2. Intro  •  Java  Collec2on  Framework  is  a  set  of  classes   and  interfaces  to  implement  data  structures  •  When  array  is  not  enough..  J  •  Lot  of  classes  and  interfaces   –  hFp://upload.wikimedia.org/wikipedia/ commons/4/41/Collec2on_Classes.jpg  
  3. 3. Core  Collec2on  Interfaces  
  4. 4. Collec2on  Interface  •  Basic  parts  of  all  collec2ons  •  add(),  remove(),  toArray(),  contains()  •  Collec2on  is  generic  
  5. 5. Three  main  type  of  Collec2on  •  List   –  Always  ordered,  may  contain  duplicates,  like  an   array  •  Set   –  Cannot  contain  duplicate  •  Map     –  Key  –  value  pairs,  random  access  to  keys  
  6. 6. List  •  List  interface  has  two  concrete  classes   –  ArrayList  –  implementa2on  uses  dynamically   resized  arrays   –  LinkedList  –  double-­‐linked  list  
  7. 7. Set  •  Set  can’t  have  duplicates  •  Couple  concrete  classes   –  HashSet     –  TreeSet  –  sorted  elements!  
  8. 8. Map  •  Key  value  pairs  •  Couple  concrete  classes     –  HashMap     –  TreeMap  -­‐  sorted  
  9. 9. How  to  iterate?  •  Use  an  iterator!    Iterator i = someCollection.iterator();while(i.hasNext()) { System.out.println(i.next());}

×