CHAPTER 5ARRAY & STRINGMr.Warawut Khangkhane-Mail: awarawut@hotmail.comSocial Media: www.facebook.com/AjWarawut
Mr.Warawut Khangkhan   Chapter 5 Array & String                                 Array & String                            ...
ARRAY                                                                          Mr.Warawut                                 ...
F F                                                             Mr.Warawut                                                ...
ONE-DIMENSIONAL ARRAY                                     Mr.Warawut                                      Khangkhanก    ก ...
ONE-DIMENSIONAL ARRAY                                                Mr.Warawut                                           ...
ONE-DIMENSIONAL ARRAY                              Mr.Warawut                               Khangkhanก ก    F F       F F(...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
ONE-DIMENSIONAL ARRAY                                               Mr.Warawut                                            ...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
METHOD      CLASS    ARRAYS                               Mr.Warawut                                Khangkhanmethod binary...
METHOD        CLASS    ARRAYS                                      Mr.Warawut                                       Khangk...
METHOD         CLASS     ARRAYS                                  Mr.Warawut                                   Khangkhanmet...
TWO-DIMENSIONAL ARRAY                                      Mr.Warawut                                       Khangkhanก   ก...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
F F            ARRAYLIST                                                                Mr.Warawut                        ...
METHOD        CLASSARRAYLIST                                         Mr.Warawut                                          K...
METHOD         CLASSARRAYLIST                                          Mr.Warawut                                         ...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
ก           F    FOR EACH LOOP                                                                Mr.Warawut                  ...
ก    F    FOR EACH LOOP                                             Mr.Warawut                                            ...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
ก       F ENUMERATED TYPES                                            Mr.Warawut                                          ...
Mr.Warawut Khangkhan   Chapter 5 Array & String                                 Array & String                            ...
Mr.Warawut                  Chapter 5 Array & String                            Array & String      Khangkhan             ...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
METHOD              CLASS   STRING                                       Mr.Warawut                                       ...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
METHOD             CLASS         STRING                                            Mr.Warawut                             ...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
METHOD        CLASS      STRING                                  Mr.Warawut                                   Khangkhanmet...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
METHOD        CLASS     STRING                                   Mr.Warawut                                    Khangkhanme...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
METHOD         CLASS        STRING                                      Mr.Warawut                                       K...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
METHOD        CLASS     STRING                                    Mr.Warawut                                     Khangkhan...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
METHOD         CLASS     STRING                                      Mr.Warawut                                       Khan...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
METHOD        CLASS      STRING                                    Mr.Warawut                                     Khangkha...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
METHOD          CLASS                   STRING                                                    Mr.Warawut              ...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
STRINGBUFFERSTRINGBUILDER                                                      Mr.Warawut                                 ...
STRINGBUFFERSTRINGBUILDER                                        Mr.Warawut                                         Khangk...
METHOD       CLASS STRINGBUFFERAND   STRINGBUILDER                                             Mr.Warawut                 ...
METHOD       CLASS STRINGBUFFERAND   STRINGBUILDER                                       Mr.Warawut                       ...
Mr.Warawut             Chapter 5 Array & String                       Array & String Khangkhan                            ...
Upcoming SlideShare
Loading in...5
×

Object-Oriented Programming 5

618

Published on

Array & String

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
618
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Object-Oriented Programming 5

  1. 1. CHAPTER 5ARRAY & STRINGMr.Warawut Khangkhane-Mail: awarawut@hotmail.comSocial Media: www.facebook.com/AjWarawut
  2. 2. Mr.Warawut Khangkhan Chapter 5 Array & String Array & String ARRAY 2
  3. 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. 4. F F Mr.Warawut KhangkhanกF F ก F F F Chapter 5 Array & String (Array of Primitive DataType) Array & String F F F F F (Array ofReference Data Type) กF F F F F1 (One-Dimensional Array) F F (Multi-Dimensional Array) 4
  5. 5. ONE-DIMENSIONAL ARRAY Mr.Warawut Khangkhanก ก F F 1 Chapter 5 Array & StringdataType [ ] arrayNameก F F F ก F ก Array & StringarrayName = new dataType[ n ];Example: int[ ] number; number = new int[5]; or 5 int number = new int[5];
  6. 6. ONE-DIMENSIONAL ARRAY Mr.Warawut Khangkhanก ก F F F F Chapter 5 Array & StringdataType[ ] arrayName = { init_value1, init_value2, …, Array & String init_value };Example: char[ ] grade = {‘A’, ‘B’, ‘C’, ‘D’, ‘F’}; 6
  7. 7. ONE-DIMENSIONAL ARRAY Mr.Warawut Khangkhanก ก F F F F( F) Chapter 5 Array & StringarrayName[0] = init_value1;arrayName[1] = init_value2; Array & String…arrayName[n-1] = init_valueExample: char[ ] grade; grade = new char[2]; grade[0] = ‘A’ 7 grade[1] = ‘B’
  8. 8. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 8
  9. 9. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 9
  10. 10. ONE-DIMENSIONAL ARRAY Mr.Warawut Khangkhanก F ก F F F F F for Chapter 5 Array & Stringfor (int i = 0; i < arrayName.length; i++) { statements; Array & String};length ˈ method F ก F F 10
  11. 11. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 11
  12. 12. METHOD CLASS ARRAYS Mr.Warawut Khangkhanmethod binarySearch( ) – F ก ก array Chapter 5 Array & String arrayName.length; n = arrayName.length; Array & Stringmethod sort( ) – Farray ก F ก Arrays.sort(arrayName); Arrays.sort(arrayName); 12
  13. 13. METHOD CLASS ARRAYS Mr.Warawut Khangkhanmethod binarySearch( ) – F ก FF 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. 14. METHOD CLASS ARRAYS Mr.Warawut Khangkhanmethod equals( ) – F FF 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. 15. TWO-DIMENSIONAL ARRAY Mr.Warawut Khangkhanก ก F F 2 Chapter 5 Array & StringdataType [ ][ ] arrayNameก F F F ก F ก Array & StringarrayName = new dataType[ m ][ n ];Example: int[ ][ ] number; number = new int[2][4]; 15
  16. 16. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 16
  17. 17. F F ARRAYLIST Mr.Warawut KhangkhanArrayList ˈ 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. 18. METHOD CLASSARRAYLIST Mr.Warawut Khangkhanmethod size( ) – กArrayList Chapter 5 Array & String arrayListName.size( n = arrayListName.size( ); Array & Stringmethod add( ) – F ก ArrayList arrayListName.add(objectValue); arrayListName.add(objectValue); or arrayListName.add(index, arrayListName.add(index,objectValue);objectValue); 18
  19. 19. METHOD CLASSARRAYLIST Mr.Warawut Khangkhanmethod get( ) – F ก ArrayList F F ก Chapter 5 Array & String objectValue =arrayListName.get(index);arrayListName.get(index); Array & Stringmethod remove( ) – F ก ArrayListArrayList 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. 20. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 20
  21. 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. 22. ก F FOR EACH LOOP Mr.Warawut Khangkhan Chapter 5 Array & Stringfor (arrayType arrayValue : arrayName) { statement; Array & String}arrayType ˈ F array ArrayListarrayValue ˈ F F F FarrayName ˈ array ArrayLit 22
  23. 23. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 23
  24. 24. ก F ENUMERATED TYPES Mr.Warawut Khangkhan ˈ F F F ก กF F F F ก ˈ F F Chapter 5 Array & String Array & StringenumName {value-1, value-2, …, value-n} Ch05 05_ Example Source Code: Ch05_08 24
  25. 25. Mr.Warawut Khangkhan Chapter 5 Array & String Array & String STRING 25
  26. 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. 27. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 27
  28. 28. METHOD CLASS STRING Mr.Warawut Khangkhanmethod equals( ) – F FF 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. 29. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 29
  30. 30. METHOD CLASS STRING Mr.Warawut Khangkhanmethod 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. 31. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 31
  32. 32. METHOD CLASS STRING Mr.Warawut Khangkhanmethod 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. 33. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 33
  34. 34. METHOD CLASS STRING Mr.Warawut Khangkhanmethod substring( ) – F F String F ˈ F F Chapter 5 Array & String str2 str1 str2 = str1.substring(x, y); Array & String 34
  35. 35. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 35
  36. 36. METHOD CLASS STRING Mr.Warawut Khangkhanmethod replace( ) – F FString 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. 37. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 37
  38. 38. METHOD CLASS STRING Mr.Warawut Khangkhanmethod toUpperCase( ) – F F String F ˈ ก F F Chapter 5 Array & String str2 str1 str2 = str1.toUpperCase( ); Array & Stringmethod toLowerCase( ) – FF String F ˈ ก F ก str2 str1 str2 = str1.toLowerCase( );method length( ) – F ก F String n = str.length( ); str.length( 38
  39. 39. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 39
  40. 40. METHOD CLASS STRING Mr.Warawut Khangkhanmethod charAt( ) – F FF ก F String F F ก Chapter 5 Array & String str.charAt(index); ch = str.charAt(index); Array & Stringmethod indexOf( ) – F FF F ก F String index = str.indexOf(ch); str.indexOf(ch); 40
  41. 41. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 41
  42. 42. METHOD CLASS STRING Mr.Warawut Khangkhanmethod startsWith( ) – FF F F String Chapter 5 Array & String str1.startsWith(str2 result = str1.startsWith(str2); Array & StringMethod endsWith( ) – FF F F F String str1.endsWith(str2 result = str1.endsWith(str2); result F ˈ True False 42
  43. 43. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 43
  44. 44. METHOD CLASS STRING Mr.Warawut Khangkhanmethod lastIndexOf( ) – F F F F F ก F Chapter 5 Array & StringString Array & String index = str.lastIndexOf(ch); str.lastIndexOf(ch); index ˈ F F ก ch F str ก F ก ch F F ˈ 44
  45. 45. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 45
  46. 46. STRINGBUFFERSTRINGBUILDER Mr.Warawut Khangkhanclass 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. 47. STRINGBUFFERSTRINGBUILDER Mr.Warawut Khangkhanclass StringBuilder ก ก F StringBuffer F Chapter 5 Array & String F กF ก StringBuffer Array & Stringclass StringBuffer ก F ก F ThreadSynchronization F F F ก F classStringBuilder 47
  48. 48. METHOD CLASS STRINGBUFFERAND 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. 49. METHOD CLASS STRINGBUFFERAND 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. 50. Mr.Warawut Chapter 5 Array & String Array & String Khangkhan 50
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×