SlideShare a Scribd company logo
Lecture 8
More on collections




           Object Oriented Programming
            Eastern University, Dhaka
                    Md. Raihan Kibria
LinkedList
   LinkedList is just like ArrayList; however, it
    was designed to make add/remove faster
    and efficient
   Has these methods:
      addFirst
      AddLast
      removeFirst
      removeLast
Who implements List interface
   ArrayList
   LinkedList
   Vector
   Stack
Sets
   Examples are HashSet, TreeSet

   Difference between Set and List
      A list can have duplicate objects
      Set cannot have duplicate objects
      See example in the next slide
Output

                       size of set: 4
                       0
                       1
                       2
                       3
                       size of list: 5
                       0
                       1
                       2
                       3
                       3
We can see set did not add duplicate element
public class SetDemo {

 public static void main(String[] args) {
   Set<Integer>set = new HashSet<Integer>();
   List<Integer>list = new ArrayList<Integer>();

     for (int i=0; i<4; i++){
       set.add(new Integer(i));
       list.add(new Integer(i));
     }

     set.add(3);
     list.add(3);

     System.out.println("size of set: " + set.size());
     for (int i=0; i<set.size(); i++)
       System.out.println(set.toArray()[i]);

     System.out.println("size of list: " + list.size());
     for (int i=0; i<list.size(); i++)
       System.out.println(list.get(i));
     }
 }

Output in the following slide
Map interface
 Object to a map are key,value pairs
 For example,
<dhaka, 02>
<chittagong, 031>
<sylhet, 032>
 Two most common map implementations
  are HashMap and TreeMap
HashMap example
public class MapDemo {
  public static void main(String[] args) {
    Map<String, Integer>map = new HashMap<String, Integer>();
    map.put("Dhaka", 2);
    map.put("Chittagong", 31);
    map.put("Sylhet", 32);

        System.out.println(map.get("Chittagong"));
        System.out.println(map.get("Comilla"));
    }
}




    Output is:
    31
    null
Inner classes

Next slide: a demo without using inner class
public class ButtonListenerDemo {

    public static void main(String[] args) {
      JFrame jframe = new JFrame();
      jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      jframe.setBounds(0, 0, 300, 200);
      jframe.setLayout(new FlowLayout());

        JButton jbutton = new JButton("Test button");
        jframe.add(jbutton);
        jbutton.addActionListener(new ButtonListener());

        JTextField jtext = new JTextField();
        jframe.getContentPane().add(jtext);
        jtext.setText("Hello");
        jframe.setVisible(true);
    }
}

class ButtonListener implements ActionListener{

@Override
public void actionPerformed(ActionEvent arg0) {
    JOptionPane.showMessageDialog(null,
      "Eggs are not supposed to be green.");
  }
}
After Run the Program




After Clicking the Test Button
public class ButtonListenerDemo2 {

    public static void main(String[] args) {
      JFrame jframe = new JFrame();
      jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      jframe.setBounds(0, 0, 300, 200);
      jframe.setLayout(new FlowLayout());

        final JTextField jtext = new JTextField();
        jframe.getContentPane().add(jtext);
        jtext.setText("Hello");
        jframe.setVisible(true);

        final int i=0;
        class MyButtonListener implements ActionListener{

            int j = i;
            @Override
            public void actionPerformed(ActionEvent arg0) {
              jtext.setText(String.valueOf(j++));
            }
        }

        JButton jbutton = new JButton("Test button");
        jframe.add(jbutton);
        jbutton.addActionListener(new MyButtonListener());
    }
}
After Run the Program




After Clicking the Test Button for
              Once
After Clicking the Test Button for
              Twice




After Clicking the Test Button for
              Thrice
Advantages of using Inner class

Improves code-cohesion
Provides convenience to the developer

More Related Content

What's hot

The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
Mahmoud Samir Fayed
 
Closure, Higher-order function in Swift
Closure, Higher-order function in SwiftClosure, Higher-order function in Swift
Closure, Higher-order function in Swift
SeongGyu Jo
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)
진성 오
 
Python Dictionary
Python DictionaryPython Dictionary
Python Dictionary
Colin Su
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
Rick Copeland
 
ScalaFlavor4J
ScalaFlavor4JScalaFlavor4J
ScalaFlavor4J
Kazuhiro Sera
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
Mahmoud Samir Fayed
 
Objeck
ObjeckObjeck
Objeck
Zapry Zherba
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
Narong Intiruk
 
PythonOOP
PythonOOPPythonOOP
PythonOOP
Veera Pendyala
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Marian Marinov
 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1
Giovanni Della Lunga
 
Grammatical Optimization
Grammatical OptimizationGrammatical Optimization
Grammatical Optimization
adil raja
 
Introduction to python programming 2
Introduction to python programming   2Introduction to python programming   2
Introduction to python programming 2
Giovanni Della Lunga
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
Wei-Yuan Chang
 
Elixir formatter Internals
Elixir formatter InternalsElixir formatter Internals
Elixir formatter Internals
Pedro Medeiros
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
ssuserd6b1fd
 
Macrobrew: Clojure macros distilled
Macrobrew: Clojure macros distilledMacrobrew: Clojure macros distilled
Macrobrew: Clojure macros distilled
abhinavomprakash10
 
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD  MAKING IN PAYTHON BY ROHIT MALAVNOTEPAD  MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
Rohit malav
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
ssuserd6b1fd
 

What's hot (20)

The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
Closure, Higher-order function in Swift
Closure, Higher-order function in SwiftClosure, Higher-order function in Swift
Closure, Higher-order function in Swift
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)
 
Python Dictionary
Python DictionaryPython Dictionary
Python Dictionary
 
Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)Python Functions (PyAtl Beginners Night)
Python Functions (PyAtl Beginners Night)
 
ScalaFlavor4J
ScalaFlavor4JScalaFlavor4J
ScalaFlavor4J
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
 
Objeck
ObjeckObjeck
Objeck
 
Begin with Python
Begin with PythonBegin with Python
Begin with Python
 
PythonOOP
PythonOOPPythonOOP
PythonOOP
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1
 
Grammatical Optimization
Grammatical OptimizationGrammatical Optimization
Grammatical Optimization
 
Introduction to python programming 2
Introduction to python programming   2Introduction to python programming   2
Introduction to python programming 2
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
Elixir formatter Internals
Elixir formatter InternalsElixir formatter Internals
Elixir formatter Internals
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
Macrobrew: Clojure macros distilled
Macrobrew: Clojure macros distilledMacrobrew: Clojure macros distilled
Macrobrew: Clojure macros distilled
 
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD  MAKING IN PAYTHON BY ROHIT MALAVNOTEPAD  MAKING IN PAYTHON BY ROHIT MALAV
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
 

Viewers also liked

Presentacion viernes 20 [compatibility mode]
Presentacion viernes 20 [compatibility mode]Presentacion viernes 20 [compatibility mode]
Presentacion viernes 20 [compatibility mode]edyarr
 
Calendario portada
Calendario portadaCalendario portada
Calendario portadaIsabel Jb
 
Cwgd
CwgdCwgd
Cwgd
cwgday
 

Viewers also liked (9)

Oop lecture6
Oop lecture6Oop lecture6
Oop lecture6
 
Presentacion viernes 20 [compatibility mode]
Presentacion viernes 20 [compatibility mode]Presentacion viernes 20 [compatibility mode]
Presentacion viernes 20 [compatibility mode]
 
Calendario portada
Calendario portadaCalendario portada
Calendario portada
 
Cwgd
CwgdCwgd
Cwgd
 
Oop lecture2
Oop lecture2Oop lecture2
Oop lecture2
 
Oop lecture9 11
Oop lecture9 11Oop lecture9 11
Oop lecture9 11
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
Oop lecture1
Oop lecture1Oop lecture1
Oop lecture1
 
Oop lecture9 12
Oop lecture9 12Oop lecture9 12
Oop lecture9 12
 

Similar to Oop lecture8

I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdf
arpitcomputronics
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
fantoosh1
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
Kuldeep Jain
 
Why following sort does not work (It does not sort last 2 - 3 numbe.pdf
Why following sort does not work (It does not sort last 2 - 3 numbe.pdfWhy following sort does not work (It does not sort last 2 - 3 numbe.pdf
Why following sort does not work (It does not sort last 2 - 3 numbe.pdf
gopalk44
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1sotlsoc
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
alliedscorporation
 
07+08slide.pptx
07+08slide.pptx07+08slide.pptx
07+08slide.pptx
MURADSANJOUM
 
I am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdfI am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdf
seamusschwaabl99557
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
arshin9
 
T
TT
Java Collections
Java CollectionsJava Collections
Java Collections
rithustutorials
 
Program klik sederhana
Program klik sederhanaProgram klik sederhana
Program klik sederhana
Henfry Kai
 

Similar to Oop lecture8 (20)

Oop lecture7
Oop lecture7Oop lecture7
Oop lecture7
 
I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdf
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
CORE JAVA-2
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Why following sort does not work (It does not sort last 2 - 3 numbe.pdf
Why following sort does not work (It does not sort last 2 - 3 numbe.pdfWhy following sort does not work (It does not sort last 2 - 3 numbe.pdf
Why following sort does not work (It does not sort last 2 - 3 numbe.pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
Java awt
Java awtJava awt
Java awt
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
 
07+08slide.pptx
07+08slide.pptx07+08slide.pptx
07+08slide.pptx
 
I am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdfI am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdf
 
Java
JavaJava
Java
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
Awt
AwtAwt
Awt
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
T
TT
T
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Program klik sederhana
Program klik sederhanaProgram klik sederhana
Program klik sederhana
 
Bar graph
Bar graphBar graph
Bar graph
 

More from Shahriar Robbani

Group111
Group111Group111
SQL
SQLSQL

More from Shahriar Robbani (7)

Group111
Group111Group111
Group111
 
SQL
SQLSQL
SQL
 
Oop lecture9 10
Oop lecture9 10Oop lecture9 10
Oop lecture9 10
 
Oop lecture4
Oop lecture4Oop lecture4
Oop lecture4
 
Oop lecture9
Oop lecture9Oop lecture9
Oop lecture9
 
Oop lecture5
Oop lecture5Oop lecture5
Oop lecture5
 
Oop lecture3
Oop lecture3Oop lecture3
Oop lecture3
 

Recently uploaded

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 

Recently uploaded (20)

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 

Oop lecture8

  • 1. Lecture 8 More on collections Object Oriented Programming Eastern University, Dhaka Md. Raihan Kibria
  • 2. LinkedList  LinkedList is just like ArrayList; however, it was designed to make add/remove faster and efficient  Has these methods:  addFirst  AddLast  removeFirst  removeLast
  • 3. Who implements List interface  ArrayList  LinkedList  Vector  Stack
  • 4. Sets  Examples are HashSet, TreeSet  Difference between Set and List  A list can have duplicate objects  Set cannot have duplicate objects  See example in the next slide
  • 5. Output size of set: 4 0 1 2 3 size of list: 5 0 1 2 3 3 We can see set did not add duplicate element
  • 6. public class SetDemo { public static void main(String[] args) { Set<Integer>set = new HashSet<Integer>(); List<Integer>list = new ArrayList<Integer>(); for (int i=0; i<4; i++){ set.add(new Integer(i)); list.add(new Integer(i)); } set.add(3); list.add(3); System.out.println("size of set: " + set.size()); for (int i=0; i<set.size(); i++) System.out.println(set.toArray()[i]); System.out.println("size of list: " + list.size()); for (int i=0; i<list.size(); i++) System.out.println(list.get(i)); } } Output in the following slide
  • 7. Map interface  Object to a map are key,value pairs  For example, <dhaka, 02> <chittagong, 031> <sylhet, 032>  Two most common map implementations are HashMap and TreeMap
  • 8. HashMap example public class MapDemo { public static void main(String[] args) { Map<String, Integer>map = new HashMap<String, Integer>(); map.put("Dhaka", 2); map.put("Chittagong", 31); map.put("Sylhet", 32); System.out.println(map.get("Chittagong")); System.out.println(map.get("Comilla")); } } Output is: 31 null
  • 9. Inner classes Next slide: a demo without using inner class
  • 10. public class ButtonListenerDemo { public static void main(String[] args) { JFrame jframe = new JFrame(); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setBounds(0, 0, 300, 200); jframe.setLayout(new FlowLayout()); JButton jbutton = new JButton("Test button"); jframe.add(jbutton); jbutton.addActionListener(new ButtonListener()); JTextField jtext = new JTextField(); jframe.getContentPane().add(jtext); jtext.setText("Hello"); jframe.setVisible(true); } } class ButtonListener implements ActionListener{ @Override public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(null, "Eggs are not supposed to be green."); } }
  • 11. After Run the Program After Clicking the Test Button
  • 12. public class ButtonListenerDemo2 { public static void main(String[] args) { JFrame jframe = new JFrame(); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setBounds(0, 0, 300, 200); jframe.setLayout(new FlowLayout()); final JTextField jtext = new JTextField(); jframe.getContentPane().add(jtext); jtext.setText("Hello"); jframe.setVisible(true); final int i=0; class MyButtonListener implements ActionListener{ int j = i; @Override public void actionPerformed(ActionEvent arg0) { jtext.setText(String.valueOf(j++)); } } JButton jbutton = new JButton("Test button"); jframe.add(jbutton); jbutton.addActionListener(new MyButtonListener()); } }
  • 13. After Run the Program After Clicking the Test Button for Once
  • 14. After Clicking the Test Button for Twice After Clicking the Test Button for Thrice
  • 15. Advantages of using Inner class Improves code-cohesion Provides convenience to the developer