1 / 17

Arrays

Arrays. A list of values. Conceptually, a continuous memory space. public String() {   this.offset = 0;   this.count = 0;   this.value = new char[0];   }. i. e. C. o. c. n. e. c. u. e. p. m. r. S. t. String Name = new String (“Computer Science”);. name. “Computer Science”.

celina
Download Presentation

Arrays

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Arrays A list of values Conceptually, a continuous memory space

  2. public String() {  this.offset = 0;   this.count = 0;   this.value = new char[0];   }

  3. i e C o c n e c u e p m r S t String Name = new String (“Computer Science”); name “Computer Science” name 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 “Computer Science”.subString(4,8) returns “uter “ name.subString(4,8) returns “uter”

  4. 1000 numbers • smallest

  5. int[] height = new int[11] • int[] does not includes the size • Instantiation height using new Bound checking – automatic height[index] If index = 10 If index = 12 ArrayIndexOUtOfBoundsException

  6. int[] height; • int height[]; • int[] scores = {87,98,68,87,65,100} • Char[] vowels = {‘A’, ‘E’, ‘I’, ’O’, ’U’}

  7. Array as parameters • Array is an object (call by reference) • copy the reference • call by value if array element

  8. Arrays of objects • String[] words = new String[5]; words

  9. For (int index = 0; index < LIMIT; index++) • system.out.println(list[index]); For (int value : list) System.out.println(value);

  10. Grade Grade Range

  11. int[] anArray ; • byte[] anArrayOfBytes; • short[] anArrayOfShorts; • long[] anArrayOfLongs; • float[] • char[] anArrayOfChars; • String[] anArrayOfStrings;

  12. Using final tag. for(index = 0; index < final; index ++) section= scan.nextInt(); Read data until the read data is meaningless For example if the section number is 0, stop section = scan.nextInt(); While (section != 0) { statement(s); section = scan,nextInt(); }

  13. Read up to 50 students5 scores / studentGrade depends on Avg.highest grade and namelowest grade and name • Student Section Private avg Private gNoA Instantiate 6 students object letterGrade lowerBound numbers names chagenumber getnumber Getname changename

  14. Multi dimension • Array whose components are themselves array • Array element is an array MArray

  15. Multi dimensional array –java does not directly support • Use array of array reference • Ragged array

  16. arraycopy • char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e', 'i', 'n', 'a', 't', 'e', 'd' }; • char[] copyTo = new char[7]; • for (i=2; i<=7; i++) • copyTo[i] = copyFrom[i];

More Related