《怪物獵人物語2破滅之翼》前期轟龍捕獲攻略
阿新 • • 發佈:2021-07-20
1.列舉
列舉指由一組固定的常量組成的型別
列舉中預設都是全域性靜態常量的取值,直接寫值,多個值使用逗號分隔
/*-----Student.java-----*/ public class Student { public Sex sex; public String name; public static void main(String[] args) { Student stu1 = new Student(); stu1.name = "趙四"; stu1.sex = Sex.MALE; Student stu2 = new Student(); stu2.name = "大腳"; stu2.sex = Sex.FEMALE; } }
/*-----Sex.java-----*/
public enum Sex {
MALE,FEMALE
}
2.包裝類
包裝類把基本資料型別轉換為物件
目的:
提供了一系列物件可以使用的方法
集合不允許存放基本資料型別資料,存放數字時,需要用包裝類
基本資料型別 | 包裝類 |
---|---|
byte | Byte |
short | Short |
int | Integer |
long | Long |
float | Float |
double | Double |
boolean | Boolean |
char | Character |
除了char包裝類之外,其他的包裝類都支援傳入一個與之對應的基本資料型別構造當前例項
char包裝類只支援傳入char型別
public static void main(String[] args) { byte b = 12; Byte b1 = new Byte(b); Byte b2 = new Byte("120"); System.out.println(b1); System.out.println(b2); Short s1 = new Short((short)555); Short s2 = new Short("2356"); Integer i1 = new Integer(2356); Integer i2 = new Integer("5623"); Long l1 = new Long(5623568989745121L); Long l2 = new Long("5689"); Float f1 = new Float(2.2); Float f2 = new Float(2.2F); Float f3 = new Float("2.2"); Double d1 = new Double(20.3); Double d2 = new Double("20.3"); Boolean bl1 = new Boolean("fAlse"); System.out.println(bl1); Boolean bl2 = new Boolean("TrUe"); System.out.println(bl2); Boolean bl3 = new Boolean("abcdefg"); System.out.println(bl3); Boolean bl4 = new Boolean(true); Character ch1 = new Character('a'); System.out.println(ch1); // A 65 a 97 Character ch2 = new Character((char)66); System.out.println(ch2); }