Java 語言“坑爹” TOP 10
往期熱門文章:
1、40 個 SpringBoot 常用注解:讓生產(chǎn)力爆表!
3、BigDecimal使用不當(dāng),造成P0事故!
推薦:https://www.xttblog.com/?p=5347
10. switch必須加上break才結(jié)束
int count = 1;
switch(count){
case 1:
System.out.println("one");
case 2:
System.out.println("two");
case 3:
System.out.println("three");
}
one
two
three
09.邏輯運(yùn)算符的“短路”現(xiàn)象
int num = 1;
System.out.println(false && ((num++)==1));
System.out.println(num);
08.數(shù)組下標(biāo)從零開始
int[] arr = new int[]{1,3,5,7,9};
for(int i=0;i<arr.length;i++){
System.out.println("the element is:"+arr[i]);
}
String str = "hello world";
System.out.println(str.charAt(1));
07.ArrayList遍歷刪除時報(bào)錯
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("abc");
list.add("bc");
list.add("bc");
list.add("abcd");
list.add("abcdef");
//報(bào)錯
int length = list.size();
for(int i = 0;i < length;i++){
if(list.get(i).equals("bc")){
list.remove(i);
}
}
}
for(int i=0;i<list.size();i++){
if(list.get(i).equals("bc")){
list.remove(i);
}
}
06.字符轉(zhuǎn)成數(shù)字的坑
char symbol = '8';
System.out.println((int) symbol);
05.while循環(huán)體的“障眼法”
int i = 0;
while(i++<3)
System.out.print("A");
System.out.print("B");
int i = 0;
while(i++<3)
System.out.print("A");System.out.print("B");
04.Integer類有緩存
public static void main(String[] args){
Integer a = 100;
Integer b = 100;
Integer c = 200;
Integer d = 200;
System.out.println(a==b);
System.out.println(c==d);
}
true
false
public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
03.空方法體導(dǎo)致死循環(huán)
int i = 1;
while(i<4){
System.out.println(i++);
}
int i = 1;
while(i<4);{
System.out.println(i++);
}
02.神奇的=+
int i = 100;
i =+ 2; //注意,加號在后面
System.out.println(i);
01.Java注釋能夠識別Unicode
public static void main(String[] args){
// \u000d System.out.println("Hello World!");
}
最近熱文閱讀:
1、40 個 SpringBoot 常用注解:讓生產(chǎn)力爆表! 2、3種常見的數(shù)據(jù)脫敏方案 3、BigDecimal使用不當(dāng),造成P0事故! 4、改造BeanUtils,優(yōu)雅實(shí)現(xiàn)List數(shù)據(jù)拷貝 5、讓人上癮的新一代開發(fā)神器,徹底告別Controller、Service、Dao等方法 6、SpringBoot 啟動時自動執(zhí)行代碼的幾種方式,還有誰不會?? 7、延時消息常見實(shí)現(xiàn)方案 8、勁爆!Java 通用泛型要來了。。 9、如何寫出讓同事吐血的代碼? 10、遭棄用的 Docker Desktop 放大招!宣布支持 Linux 關(guān)注公眾號,你想要的Java都在這里
評論
圖片
表情
