墨尔本大学java课程课件chap6.ppt
文本预览下载声明
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Some Methods Included with Every Enumerated Type (Part 3 of 3) 6-* Copyright ? 2010 Pearson Addison-Wesley. All rights reserved. The values Method To get the full potential from an enumerated type, it is often necessary to cycle through all the values of the type Every enumerated type is automatically provided with the static method values() which provides this ability It returns an array whose elements are the values of the enumerated type given in the order in which the elements are listed in the definition of the enumerated type The base type of the array that is returned is the enumerated type 6-* Copyright ? 2010 Pearson Addison-Wesley. All rights reserved. The Method values (Part 1 of 2) 6-* Copyright ? 2010 Pearson Addison-Wesley. All rights reserved. The Method values (Part 2 of 2) 6-* Copyright ? 2010 Pearson Addison-Wesley. All rights reserved. Programming Tip: Enumerated Types in switch Statements Enumerated types can be used to control a switch statement The switch control expression uses a variable of an enumerated type Case labels are the unqualified values of the same enumerated type The enumerated type control variable is set by using the static method valueOf to convert an input string to a value of the enumerated type The input string must contain all upper case letters, or be converted to all upper case letters using the toUpperCase method 6-* Copyright ? 2010 Pearson Addison-Wesley. All rights reserved. Multidimensional Arrays It is sometimes useful to have an array with more than one index Multidimensional arrays are declared and created in basically the same way as one-dimensional arrays You simply use as many square brackets as there are indices Each index must be enclosed in its own brackets double[][]table = new double[100][10]; int[][][] figure = new int[10][20][30]; Person[][] = new Person[10][100]; 6-* Copyright ? 2010 Pearson Addison-Wesley. All
显示全部