c盤清理的步驟是什么(如何清理C盤空間)
如何清理C盤空間怎么清理C盤的垃圾文件?每天上網會給電腦帶來很多臨時文件,這些垃圾文件不清理掉時間久了就會影響到電腦的運行速度。那怎
2022/12/08
包裝類是將基本數據類型封裝成一個類,包含屬性和方法
(資料圖片)
在使用過程中,會涉及到自動裝箱和自動拆箱
裝箱:將基本數據類型轉換成包裝類基本類型就自動地封裝到與它相同類型的包裝中,如:Integer i = 100;本質上,編譯器編譯時為我們添加了:Integer i = Integer.valueOf(100);拆箱:將包裝類轉換成基本數據類型包裝類對象自動轉換成基本類型數據。如:int a = new Integer(100);本質上,編譯器編譯時為我們添加了:– int a = new Integer(100).intValue();public class IntegerDemo { public static void main(String[] args) {// int a = 10;// Integer i = new Integer(10);//被拆箱了//------------------------------------------// //通過方法進行類型的轉換// Integer i2 = Integer.valueOf(a);//裝箱// int i3 = i.intValue();//拆箱//------------------------------------------// System.out.println(a == i);// Float f1 = new Float(3.14);// Double d1 = new Double(3.14); Integer i = 10; int a = i; System.out.println(a==i); }}
// int i =100;// Integer i1 = 100;// Integer i2 = 100;// Integer i3 = 200;// Integer i4 = 200;// System.out.println(i1==i2);// System.out.println(i3==i4);// 結果//true//false
看valueOf的實現
值在-128---127之間返回相同Integer
超過這個范圍后就返回??new Integer(i);?
??
// Double d1 = 1.0;// Double d2 = 1.0;// Double d3 = 2.0;// Double d4 = 2.0;// System.out.println(d1==d2);// System.out.println(d3==d4);// 結果//false//false
都返回??new?
?
注意:常量池在1.7之后放置在了堆空間之中
字符串的使用:
public class StringDemo { public static void main(String[] args) { String str = "abc"; String str2 = new String("abc");// str2 = str2.intern(); System.out.println(str==str2); System.out.println(str.equals(str2)); System.out.println(str.charAt(0)); //數組的復制過程 System.out.println(str.concat("cde")); //返回指定下標的元素 System.out.println(str.indexOf("a")); String s = "abcdefghijklmn"; System.out.println(s.substring(3)); //在截取字符串的時候,需要注意是左閉右開區間 System.out.println(s.substring(3,5)); System.out.println(s.length());//----------------------------------------------------------// String a = "abc";// String b = new String("abc");// b = b.intern();// System.out.println(a==b); String a = "abc"; String b = "def"; String c = "abcdef"; // String d1 = a+b; // System.out.println(c==d1);//false String d = (a+b).intern(); String e = "abc"+"def"; System.out.println(c==d);//true System.out.println(c==e);//true,c,e都是常量,"abcdef"在常量池里只會存在一次,因此地址相同 String f = "a" + "b" +"c"; String a1 = "a"; String a2 = "b"; String a3 = "c"; String f1 = a1+a2+a3; }}
可變字符串
StringBuffer:線程安全,效率低
StringBuilder: 線程不安全,效率高
public class StringBufferDemo { public static void main(String[] args) { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(1).append(1.234).append("abc").append(true); System.out.println(stringBuffer);//11.234abctrue System.out.println(stringBuffer.length());//13 System.out.println(stringBuffer.capacity());//16 StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("123").append(1).append(false); System.out.println(stringBuilder); }}
public class DateDemo { public static void main(String[] args) throws ParseException { Date date = new Date(); System.out.println(date); System.out.println(date.getTime()); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //將Date類按照規范轉換為字符串格式 String str = dateFormat.format(date); System.out.println(str); //將字符串轉換成對應的日期類 Date d1 = dateFormat.parse("2019-10-9 20:29:56"); System.out.println(d1); //獲取的是當前系統的時間 Calendar calendar = Calendar.getInstance(); System.out.println(calendar); //設置指定時間的日歷類 calendar.setTime(d1); System.out.println(calendar); System.out.println(calendar.get(Calendar.YEAR)); System.out.println(calendar.get(Calendar.MONTH)); System.out.println(calendar.get(Calendar.DAY_OF_MONTH)); System.out.println(calendar.get(Calendar.HOUR_OF_DAY)); System.out.println(calendar.get(Calendar.MINUTE)); System.out.println(calendar.get(Calendar.SECOND)); }}
public class MathDemo { public static void main(String[] args) { System.out.println(Math.abs(-1)); System.out.println(Math.sqrt(2)); System.out.println(Math.ceil(-3.14));//向上取整 System.out.println(Math.floor(-3.14));//向下取整 System.out.println(Math.pow(2,3));//次方 }}
public enum Gender { 男,女}
1. 只能夠取特定值中的一個
2. 使用enum關鍵字
3. 所有的枚舉類型隱性地繼承自 java.lang.Enum。(枚舉實質上還是類!而每個被枚舉的成員實質就是一個枚舉類型的實例,他們默認都是public static final的。可以直接通過枚舉類型名直接使用它們。)
public enum EventEnum { LAUNCH("launch"),PAGEVIEW("pageview"),EVENT("event"); EventEnum(String name){ this.name = name; } private String name; public void show(){ System.out.println(this.name); EventEnum[] ee = values(); for(int i = 0;i public class Test { public static void main(String[] args) { EventEnum ee = EventEnum.LAUNCH; ee.show(); String name = EventEnum.PAGEVIEW.name(); System.out.println(name); }}