SlideShare une entreprise Scribd logo
1  sur  50
Télécharger pour lire hors ligne
CHAPTER 5
ARRAY & STRING
Mr.Warawut Khangkhan
e-Mail: awarawut@hotmail.com
Social Media: www.facebook.com/AjWarawut
Mr.Warawut Khangkhan   Chapter 5 Array & String
                                 Array & String
                                            ARRAY
                                                    2
ARRAY




                                                                          Mr.Warawut
                                                                           Khangkhan
   Array (        F F) ˈ             F F          ก F
                ก F กก F   1       F F ก F




                                                                              Chapter 5 Array & String
        ก                             F (Index) ˈ     ก




                                                                                        Array & String
                      ก
            F          F F ก         F       F         F ก        F
       F                F  ก             F Index     F   F F
    F ก
Index           [0]            [1]               …        [n-1]
                                                                          3

                ก     1        ก         2       …        ก           n
F F




                                                             Mr.Warawut
                                                              Khangkhan
กF                F           ก
     F F      F




                                                                 Chapter 5 Array & String
                                  (Array of Primitive Data
Type)




                                                                           Array & String
     F F      F                      F   F (Array of
Reference Data Type)
 กF                     F F
           F F1        (One-Dimensional Array)
            F F         (Multi-Dimensional Array)
                                                             4
ONE-DIMENSIONAL ARRAY




                                     Mr.Warawut
                                      Khangkhan
ก    ก         F F      1




                                         Chapter 5 Array & String
dataType [ ] arrayName
ก             F F F ก       F    ก




                                                   Array & String
arrayName = new dataType[ n ];

Example:
   int[ ] number;
   number = new int[5];
    or                               5

    int number = new int[5];
ONE-DIMENSIONAL ARRAY




                                                Mr.Warawut
                                                 Khangkhan
ก ก      F F        F F




                                                    Chapter 5 Array & String
dataType[ ] arrayName =
    { init_value1, init_value2, …,




                                                              Array & String
    init_value };

Example:
   char[ ] grade = {‘A’, ‘B’, ‘C’, ‘D’, ‘F’};


                                                6
ONE-DIMENSIONAL ARRAY




                              Mr.Warawut
                               Khangkhan
ก ก    F F       F F( F)




                                  Chapter 5 Array & String
arrayName[0] = init_value1;
arrayName[1] = init_value2;




                                            Array & String
…
arrayName[n-1] = init_value

Example:
   char[ ] grade;
   grade = new char[2];
   grade[0] = ‘A’             7

   grade[1] = ‘B’
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        8
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        9
ONE-DIMENSIONAL ARRAY




                                               Mr.Warawut
                                                Khangkhan
ก F      ก     F      F         F F F   for




                                                 Chapter 5 Array & String
for (int i = 0; i < arrayName.length; i++) {
   statements;




                                                           Array & String
};

length   ˈ   method        F            ก
                          F F

                                               10
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        11
METHOD      CLASS    ARRAYS




                               Mr.Warawut
                                Khangkhan
method binarySearch( ) – F ก
       ก       array




                                 Chapter 5 Array & String
       arrayName.length;
   n = arrayName.length;




                                           Array & String
method sort( ) – F
array ก F       ก
   Arrays.sort(arrayName);
   Arrays.sort(arrayName);

                               12
METHOD        CLASS    ARRAYS




                                      Mr.Warawut
                                       Khangkhan
method binarySearch( ) – F ก F
F    F ก         array (      กF )




                                        Chapter 5 Array & String
   idxValue =




                                                  Array & String
   Arrays.binarySeach(arrName,
   Arrays.binarySeach(arrName,
         val);
         val);
method fill( ) – F     ก  F F    Fก
     array ก F        ก
   Arrays.fill(arrayName,
   Arrays.fill(arrayName, value);
                                      13
METHOD         CLASS     ARRAYS




                                  Mr.Warawut
                                   Khangkhan
method equals( ) – F         F
F         array




                                    Chapter 5 Array & String
   result =




                                              Array & String
   Arrays.equals(arrayName
                (arrayName1
   Arrays.equals(arrayName1,
       arrayName2
       arrayName2);


                      Ch05
                        05_
 Example Source Code: Ch05_04
                                  14
TWO-DIMENSIONAL ARRAY




                                      Mr.Warawut
                                       Khangkhan
ก   ก         F F     2




                                        Chapter 5 Array & String
dataType [ ][ ] arrayName
ก           F F F ก         F   ก




                                                  Array & String
arrayName = new dataType[ m ][ n ];

Example:
   int[ ][ ] number;
   number = new int[2][4];
                                      15
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        16
F F            ARRAYLIST




                                                                Mr.Warawut
                                                                 Khangkhan
ArrayList              ˈ     F F         ก      ก
  ก                F               F F F F              F




                                                                  Chapter 5 Array & String
             F ก                    F (index)       F




                                                                            Array & String
 F ก
ArrayList                  ก ก F                object      ˈ
array         Reference
        F
                                                                17
METHOD        CLASS
ARRAYLIST




                                         Mr.Warawut
                                          Khangkhan
method size( ) –          ก
ArrayList




                                           Chapter 5 Array & String
       arrayListName.size(
   n = arrayListName.size( );




                                                     Array & String
method add( ) –   F      ก   ArrayList
   arrayListName.add(objectValue);
   arrayListName.add(objectValue);
   or
   arrayListName.add(index,
   arrayListName.add(index,
objectValue);
objectValue);
                                         18
METHOD         CLASS
ARRAYLIST




                                          Mr.Warawut
                                           Khangkhan
method get( ) –   F   ก   ArrayList
    F   F ก




                                            Chapter 5 Array & String
    objectValue =
arrayListName.get(index);
arrayListName.get(index);




                                                      Array & String
method remove( ) – F        ก ArrayList
ArrayList       F F ก
    arrayListName.remove(index);
    arrayListName.remove(index);
method indexOf( ) – F F   F    F      ก
 F ก ArrayList
    index =
arrrayListName.indexOf(objectValue);
arrrayListName.indexOf(objectValue);      19
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        20
ก           F    FOR EACH LOOP




                                                                Mr.Warawut
                                                                 Khangkhan
        ˈ               F       F   F         F       F F
    ArrayList




                                                                  Chapter 5 Array & String
    F       ˂ ก ก ก F                   ก F       F         ก




                                                                            Array & String
                        F F
    (IndexOutOfBoundsException)
        F ก       F         ก             ก
         F ก F
                                                                21
ก    F    FOR EACH LOOP




                                             Mr.Warawut
                                              Khangkhan
                                               Chapter 5 Array & String
for (arrayType arrayValue : arrayName) {
     statement;




                                                         Array & String
}

arrayType ˈ    F     array       ArrayList
arrayValue ˈ        F F    F     F
arrayName ˈ        array       ArrayLit
                                             22
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        23
ก       F ENUMERATED TYPES




                                            Mr.Warawut
                                             Khangkhan
    ˈ        F F     F       ก     กF   F
        F F ก    ˈ F     F




                                              Chapter 5 Array & String
                                                        Array & String
enumName {value-1, value-2, …, value-n}


                         Ch05
                           05_
    Example Source Code: Ch05_08
                                            24
Mr.Warawut Khangkhan   Chapter 5 Array & String
                                 Array & String
                                            STRING
                                                     25
Mr.Warawut
                  Chapter 5 Array & String
                            Array & String
      Khangkhan
                                             26
         F


                               F
                        ก F
                        F FF
                        ˈก
                        F F
         ก


                               F
         F


                               F ก
         ก
STRING

                        F
                      F F
         F
                  ก ˈ F
         ˈ

                  ก
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        27
METHOD              CLASS   STRING




                                       Mr.Warawut
                                        Khangkhan
method equals( ) – F               F
F    String 2 F




                                         Chapter 5 Array & String
           str1.equals(str2
  result = str1.equals(str2);




                                                   Array & String
      F   F Fก       F ˈ True
      F    F F Fก      F ˈ False


                                       28
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        29
METHOD             CLASS         STRING




                                            Mr.Warawut
                                             Khangkhan
method compareTo( ) – F
       F F     String 2 F




                                              Chapter 5 Array & String
           str1.compareTo(str2
  result = str1.compareTo(str2);




                                                        Array & String
  F str1     F > str2     F ˈ       ก
   F str1     F = str2     F ˈ          F
 F str1     F < str2     F ˈ

                                            30
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        31
METHOD        CLASS      STRING




                                  Mr.Warawut
                                   Khangkhan
method concat( ) – F        F F
  String    F      +




                                    Chapter 5 Array & String
  str3   str1.concat(str2
  str3 = str1.concat(str2);




                                              Array & String
   or
   str3
   str3 = str1 + str2;
          str1   str2



                                  32
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        33
METHOD        CLASS     STRING




                                   Mr.Warawut
                                    Khangkhan
method substring( ) – F        F
  String F ˈ F   F




                                     Chapter 5 Array & String
  str2   str1
  str2 = str1.substring(x, y);




                                               Array & String
                                   34
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        35
METHOD         CLASS        STRING




                                      Mr.Warawut
                                       Khangkhan
method replace( ) – F        F
String F ˈ F     F




                                        Chapter 5 Array & String
   str2    str1.replace(str3 str4
   str2 = str1.replace(str3, str4);




                                                  Array & String
    str3 ˈ F     ก      F
    str4 ˈ F                F


                                      36
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        37
METHOD        CLASS     STRING




                                    Mr.Warawut
                                     Khangkhan
method toUpperCase( ) – F
      F      String F ˈ  ก  F F




                                      Chapter 5 Array & String
    str2     str1
    str2 = str1.toUpperCase( );




                                                Array & String
method toLowerCase( ) – F
F       String F ˈ ก    F ก
    str2     str1
    str2 = str1.toLowerCase( );
method length( ) – F            ก
  F       String
    n = str.length( );
          str.length(
                                    38
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        39
METHOD         CLASS     STRING




                                      Mr.Warawut
                                       Khangkhan
method charAt( ) – F      F
F ก     F    String         F   F ก




                                        Chapter 5 Array & String
       str.charAt(index);
  ch = str.charAt(index);




                                                  Array & String
method indexOf( ) – F      F
F    F   ก      F   String
  index = str.indexOf(ch);
          str.indexOf(ch);


                                      40
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        41
METHOD        CLASS      STRING




                                    Mr.Warawut
                                     Khangkhan
method startsWith( ) – F
F   F      F       String




                                      Chapter 5 Array & String
             str1.startsWith(str2
  result = str1.startsWith(str2);




                                                Array & String
Method endsWith( ) – F
F   F F    F     String
           str1.endsWith(str2
  result = str1.endsWith(str2);

  result      F ˈ True     False    42
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        43
METHOD          CLASS                   STRING




                                                    Mr.Warawut
                                                     Khangkhan
method lastIndexOf( ) – F                      F
      F    F    F               ก        F




                                                      Chapter 5 Array & String
String




                                                                Array & String
   index = str.lastIndexOf(ch);
           str.lastIndexOf(ch);
  index ˈ           F       F            ก    ch
   F   str              ก           F        ก ch
               F F ˈ
                                                    44
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        45
STRINGBUFFER
STRINGBUILDER




                                                      Mr.Warawut
                                                       Khangkhan
class StringBuffer ก                ก        F
       String F                 F                กF




                                                        Chapter 5 Array & String
 ก   String




                                                                  Array & String
 String F            F   F              F        ก
  ก F     F
 ก F method          F String               ˈก
   F String   F (ก                          กก F )
   F StringBuffer            String                   46
STRINGBUFFER
STRINGBUILDER




                                        Mr.Warawut
                                         Khangkhan
class StringBuilder ก ก F
        StringBuffer F




                                          Chapter 5 Array & String
      F กF ก    StringBuffer




                                                    Array & String
class StringBuffer ก
    F         ก       F        Thread
Synchronization F       F F ก F class
StringBuilder
                                        47
METHOD       CLASS STRINGBUFFER
AND   STRINGBUILDER




                                             Mr.Warawut
                                              Khangkhan
 method append( ) F                F
   F F F StringBuffer




                                               Chapter 5 Array & String
      str3
      str3 = str1.append(str2);
             str1.append(str2




                                                         Array & String
 method insert( ) F            F
   ก F F StringBuffer                    F
  F ก
      str3
      str3 = str1.insert(index, str2);
             str1               str2
                                             48
METHOD       CLASS STRINGBUFFER
AND   STRINGBUILDER




                                       Mr.Warawut
                                        Khangkhan
 method delete( ) F            F
 F     F StringBuffer              F




                                         Chapter 5 Array & String
   F ก




                                                   Array & String
      str2 = str1.delete(x, y);
      str2   str1
 method length( ) F
 ก    F StringBuffer
      int n = str.length( );
              str.length(
                                       49
Mr.Warawut
             Chapter 5 Array & String
                       Array & String
 Khangkhan
                                        50

Contenu connexe

Tendances (6)

AI Lesson 15
AI Lesson 15AI Lesson 15
AI Lesson 15
 
ON SEMI-  -CONTINUITY WHERE   {L, M, R, S}
ON SEMI-  -CONTINUITY WHERE   {L, M, R, S}ON SEMI-  -CONTINUITY WHERE   {L, M, R, S}
ON SEMI-  -CONTINUITY WHERE   {L, M, R, S}
 
Pattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix TreesPattern Matching Part One: Suffix Trees
Pattern Matching Part One: Suffix Trees
 
L0342067075
L0342067075L0342067075
L0342067075
 
AI Lesson 14
AI Lesson 14AI Lesson 14
AI Lesson 14
 
www.ijerd.com
www.ijerd.comwww.ijerd.com
www.ijerd.com
 

En vedette

Object-Oriented Programming 9
Object-Oriented Programming 9Object-Oriented Programming 9
Object-Oriented Programming 9Warawut
 
Management Information System 3
Management Information System 3Management Information System 3
Management Information System 3Warawut
 
Object-Oriented Programming 10
Object-Oriented Programming 10Object-Oriented Programming 10
Object-Oriented Programming 10Warawut
 
Management Information System 4
Management Information System 4Management Information System 4
Management Information System 4Warawut
 
Chapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemChapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemWarawut
 
Business Computer Project 4
Business Computer Project 4Business Computer Project 4
Business Computer Project 4Warawut
 
Business Computer Project 2
Business Computer Project 2Business Computer Project 2
Business Computer Project 2Warawut
 
การใช้ตัวแปรอาร์เรย์ (Array) ใน VB.NET 2005 Express Editor
การใช้ตัวแปรอาร์เรย์ (Array) ใน VB.NET 2005 Express Editorการใช้ตัวแปรอาร์เรย์ (Array) ใน VB.NET 2005 Express Editor
การใช้ตัวแปรอาร์เรย์ (Array) ใน VB.NET 2005 Express EditorWarawut
 
Database design
Database designDatabase design
Database designWarawut
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5Warawut
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6Warawut
 

En vedette (11)

Object-Oriented Programming 9
Object-Oriented Programming 9Object-Oriented Programming 9
Object-Oriented Programming 9
 
Management Information System 3
Management Information System 3Management Information System 3
Management Information System 3
 
Object-Oriented Programming 10
Object-Oriented Programming 10Object-Oriented Programming 10
Object-Oriented Programming 10
 
Management Information System 4
Management Information System 4Management Information System 4
Management Information System 4
 
Chapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemChapter 2 Strategy & Information System
Chapter 2 Strategy & Information System
 
Business Computer Project 4
Business Computer Project 4Business Computer Project 4
Business Computer Project 4
 
Business Computer Project 2
Business Computer Project 2Business Computer Project 2
Business Computer Project 2
 
การใช้ตัวแปรอาร์เรย์ (Array) ใน VB.NET 2005 Express Editor
การใช้ตัวแปรอาร์เรย์ (Array) ใน VB.NET 2005 Express Editorการใช้ตัวแปรอาร์เรย์ (Array) ใน VB.NET 2005 Express Editor
การใช้ตัวแปรอาร์เรย์ (Array) ใน VB.NET 2005 Express Editor
 
Database design
Database designDatabase design
Database design
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6
 

Plus de Warawut

Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8Warawut
 
Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7Warawut
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6Warawut
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3Warawut
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4Warawut
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1Warawut
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MISWarawut
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3Warawut
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2Warawut
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1Warawut
 
Upload File
Upload FileUpload File
Upload FileWarawut
 
Session and Cookie
Session and CookieSession and Cookie
Session and CookieWarawut
 
Form Validation
Form ValidationForm Validation
Form ValidationWarawut
 
Tips & Track
Tips & TrackTips & Track
Tips & TrackWarawut
 
Edit & Delete Data
Edit & Delete DataEdit & Delete Data
Edit & Delete DataWarawut
 
Search Data
Search DataSearch Data
Search DataWarawut
 
Retrieve Data
Retrieve DataRetrieve Data
Retrieve DataWarawut
 
Additional Information
Additional InformationAdditional Information
Additional InformationWarawut
 
Connect MySQL
Connect MySQLConnect MySQL
Connect MySQLWarawut
 

Plus de Warawut (20)

Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8
 
Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MIS
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2
 
Object-Oriented Programming 1
Object-Oriented Programming 1Object-Oriented Programming 1
Object-Oriented Programming 1
 
Upload File
Upload FileUpload File
Upload File
 
Login
LoginLogin
Login
 
Session and Cookie
Session and CookieSession and Cookie
Session and Cookie
 
Form Validation
Form ValidationForm Validation
Form Validation
 
Tips & Track
Tips & TrackTips & Track
Tips & Track
 
Edit & Delete Data
Edit & Delete DataEdit & Delete Data
Edit & Delete Data
 
Search Data
Search DataSearch Data
Search Data
 
Retrieve Data
Retrieve DataRetrieve Data
Retrieve Data
 
Additional Information
Additional InformationAdditional Information
Additional Information
 
Connect MySQL
Connect MySQLConnect MySQL
Connect MySQL
 

Dernier

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 

Dernier (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

Object-Oriented Programming 5

  • 1. CHAPTER 5 ARRAY & STRING Mr.Warawut Khangkhan e-Mail: awarawut@hotmail.com Social Media: www.facebook.com/AjWarawut
  • 2. Mr.Warawut Khangkhan Chapter 5 Array & String Array & String ARRAY 2
  • 3. ARRAY Mr.Warawut Khangkhan Array ( F F) ˈ F F ก F ก F กก F 1 F F ก F Chapter 5 Array & String ก F (Index) ˈ ก Array & String ก F F F ก F F F ก F F F ก F Index F F F F ก Index [0] [1] … [n-1] 3 ก 1 ก 2 … ก n
  • 4. F F Mr.Warawut Khangkhan กF F ก F F F Chapter 5 Array & String (Array of Primitive Data Type) Array & String F F F F F (Array of Reference Data Type) กF F F F F1 (One-Dimensional Array) F F (Multi-Dimensional Array) 4
  • 5. ONE-DIMENSIONAL ARRAY Mr.Warawut Khangkhan ก ก F F 1 Chapter 5 Array & String dataType [ ] arrayName ก F F F ก F ก Array & String arrayName = new dataType[ n ]; Example: int[ ] number; number = new int[5]; or 5 int number = new int[5];
  • 6. ONE-DIMENSIONAL ARRAY Mr.Warawut Khangkhan ก ก F F F F Chapter 5 Array & String dataType[ ] arrayName = { init_value1, init_value2, …, Array & String init_value }; Example: char[ ] grade = {‘A’, ‘B’, ‘C’, ‘D’, ‘F’}; 6
  • 7. ONE-DIMENSIONAL ARRAY Mr.Warawut Khangkhan ก ก F F F F( F) Chapter 5 Array & String arrayName[0] = init_value1; arrayName[1] = init_value2; Array & String … arrayName[n-1] = init_value Example: char[ ] grade; grade = new char[2]; grade[0] = ‘A’ 7 grade[1] = ‘B’
  • 8. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 8
  • 9. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 9
  • 10. ONE-DIMENSIONAL ARRAY Mr.Warawut Khangkhan ก F ก F F F F F for Chapter 5 Array & String for (int i = 0; i < arrayName.length; i++) { statements; Array & String }; length ˈ method F ก F F 10
  • 11. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 11
  • 12. METHOD CLASS ARRAYS Mr.Warawut Khangkhan method binarySearch( ) – F ก ก array Chapter 5 Array & String arrayName.length; n = arrayName.length; Array & String method sort( ) – F array ก F ก Arrays.sort(arrayName); Arrays.sort(arrayName); 12
  • 13. METHOD CLASS ARRAYS Mr.Warawut Khangkhan method binarySearch( ) – F ก F F F ก array ( กF ) Chapter 5 Array & String idxValue = Array & String Arrays.binarySeach(arrName, Arrays.binarySeach(arrName, val); val); method fill( ) – F ก F F Fก array ก F ก Arrays.fill(arrayName, Arrays.fill(arrayName, value); 13
  • 14. METHOD CLASS ARRAYS Mr.Warawut Khangkhan method equals( ) – F F F array Chapter 5 Array & String result = Array & String Arrays.equals(arrayName (arrayName1 Arrays.equals(arrayName1, arrayName2 arrayName2); Ch05 05_ Example Source Code: Ch05_04 14
  • 15. TWO-DIMENSIONAL ARRAY Mr.Warawut Khangkhan ก ก F F 2 Chapter 5 Array & String dataType [ ][ ] arrayName ก F F F ก F ก Array & String arrayName = new dataType[ m ][ n ]; Example: int[ ][ ] number; number = new int[2][4]; 15
  • 16. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 16
  • 17. F F ARRAYLIST Mr.Warawut Khangkhan ArrayList ˈ F F ก ก ก F F F F F F Chapter 5 Array & String F ก F (index) F Array & String F ก ArrayList ก ก F object ˈ array Reference F 17
  • 18. METHOD CLASS ARRAYLIST Mr.Warawut Khangkhan method size( ) – ก ArrayList Chapter 5 Array & String arrayListName.size( n = arrayListName.size( ); Array & String method add( ) – F ก ArrayList arrayListName.add(objectValue); arrayListName.add(objectValue); or arrayListName.add(index, arrayListName.add(index, objectValue); objectValue); 18
  • 19. METHOD CLASS ARRAYLIST Mr.Warawut Khangkhan method get( ) – F ก ArrayList F F ก Chapter 5 Array & String objectValue = arrayListName.get(index); arrayListName.get(index); Array & String method remove( ) – F ก ArrayList ArrayList F F ก arrayListName.remove(index); arrayListName.remove(index); method indexOf( ) – F F F F ก F ก ArrayList index = arrrayListName.indexOf(objectValue); arrrayListName.indexOf(objectValue); 19
  • 20. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 20
  • 21. F FOR EACH LOOP Mr.Warawut Khangkhan ˈ F F F F F F ArrayList Chapter 5 Array & String F ˂ ก ก ก F ก F F ก Array & String F F (IndexOutOfBoundsException) F ก F ก ก F ก F 21
  • 22. F FOR EACH LOOP Mr.Warawut Khangkhan Chapter 5 Array & String for (arrayType arrayValue : arrayName) { statement; Array & String } arrayType ˈ F array ArrayList arrayValue ˈ F F F F arrayName ˈ array ArrayLit 22
  • 23. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 23
  • 24. F ENUMERATED TYPES Mr.Warawut Khangkhan ˈ F F F ก กF F F F ก ˈ F F Chapter 5 Array & String Array & String enumName {value-1, value-2, …, value-n} Ch05 05_ Example Source Code: Ch05_08 24
  • 25. Mr.Warawut Khangkhan Chapter 5 Array & String Array & String STRING 25
  • 26. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 26 F F ก F F FF ˈก F F ก F F F ก ก STRING F F F F ก ˈ F ˈ ก
  • 27. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 27
  • 28. METHOD CLASS STRING Mr.Warawut Khangkhan method equals( ) – F F F String 2 F Chapter 5 Array & String str1.equals(str2 result = str1.equals(str2); Array & String F F Fก F ˈ True F F F Fก F ˈ False 28
  • 29. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 29
  • 30. METHOD CLASS STRING Mr.Warawut Khangkhan method compareTo( ) – F F F String 2 F Chapter 5 Array & String str1.compareTo(str2 result = str1.compareTo(str2); Array & String F str1 F > str2 F ˈ ก F str1 F = str2 F ˈ F F str1 F < str2 F ˈ 30
  • 31. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 31
  • 32. METHOD CLASS STRING Mr.Warawut Khangkhan method concat( ) – F F F String F + Chapter 5 Array & String str3 str1.concat(str2 str3 = str1.concat(str2); Array & String or str3 str3 = str1 + str2; str1 str2 32
  • 33. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 33
  • 34. METHOD CLASS STRING Mr.Warawut Khangkhan method substring( ) – F F String F ˈ F F Chapter 5 Array & String str2 str1 str2 = str1.substring(x, y); Array & String 34
  • 35. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 35
  • 36. METHOD CLASS STRING Mr.Warawut Khangkhan method replace( ) – F F String F ˈ F F Chapter 5 Array & String str2 str1.replace(str3 str4 str2 = str1.replace(str3, str4); Array & String str3 ˈ F ก F str4 ˈ F F 36
  • 37. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 37
  • 38. METHOD CLASS STRING Mr.Warawut Khangkhan method toUpperCase( ) – F F String F ˈ ก F F Chapter 5 Array & String str2 str1 str2 = str1.toUpperCase( ); Array & String method toLowerCase( ) – F F String F ˈ ก F ก str2 str1 str2 = str1.toLowerCase( ); method length( ) – F ก F String n = str.length( ); str.length( 38
  • 39. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 39
  • 40. METHOD CLASS STRING Mr.Warawut Khangkhan method charAt( ) – F F F ก F String F F ก Chapter 5 Array & String str.charAt(index); ch = str.charAt(index); Array & String method indexOf( ) – F F F F ก F String index = str.indexOf(ch); str.indexOf(ch); 40
  • 41. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 41
  • 42. METHOD CLASS STRING Mr.Warawut Khangkhan method startsWith( ) – F F F F String Chapter 5 Array & String str1.startsWith(str2 result = str1.startsWith(str2); Array & String Method endsWith( ) – F F F F F String str1.endsWith(str2 result = str1.endsWith(str2); result F ˈ True False 42
  • 43. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 43
  • 44. METHOD CLASS STRING Mr.Warawut Khangkhan method lastIndexOf( ) – F F F F F ก F Chapter 5 Array & String String Array & String index = str.lastIndexOf(ch); str.lastIndexOf(ch); index ˈ F F ก ch F str ก F ก ch F F ˈ 44
  • 45. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 45
  • 46. STRINGBUFFER STRINGBUILDER Mr.Warawut Khangkhan class StringBuffer ก ก F String F F กF Chapter 5 Array & String ก String Array & String String F F F F ก ก F F ก F method F String ˈก F String F (ก กก F ) F StringBuffer String 46
  • 47. STRINGBUFFER STRINGBUILDER Mr.Warawut Khangkhan class StringBuilder ก ก F StringBuffer F Chapter 5 Array & String F กF ก StringBuffer Array & String class StringBuffer ก F ก F Thread Synchronization F F F ก F class StringBuilder 47
  • 48. METHOD CLASS STRINGBUFFER AND STRINGBUILDER Mr.Warawut Khangkhan method append( ) F F F F F StringBuffer Chapter 5 Array & String str3 str3 = str1.append(str2); str1.append(str2 Array & String method insert( ) F F ก F F StringBuffer F F ก str3 str3 = str1.insert(index, str2); str1 str2 48
  • 49. METHOD CLASS STRINGBUFFER AND STRINGBUILDER Mr.Warawut Khangkhan method delete( ) F F F F StringBuffer F Chapter 5 Array & String F ก Array & String str2 = str1.delete(x, y); str2 str1 method length( ) F ก F StringBuffer int n = str.length( ); str.length( 49
  • 50. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 50