Labmda表达式:
Runnable runnable =new Runnable(){
public void run(){
//123
}
}
变:
Runnable runnable =()->{
//123
}
“123”为多句代码,可以写上括号,如果仅一句,可以不写。
获得小数位数:
经测试,使用小数(1.01)通过使用“.”进行split操作后,得到的数组为空,原因在于String的split方法
public String[] split(String regex, int limit) {
/* fastpath if the regex is a
(1)one-char String and this character is not one of the
RegEx's meta characters ".$|()[{^?*+\\", or
(2)two-char String and the first char is the backslash and
the second is not the ascii digit or ascii letter.
*/
char ch = 0;
if (((regex.value.length == 1 &&
".$|()[{^?*+\\".indexOf(ch = regex.charAt(0)) == -1) ||
(regex.length() == 2 &&
regex.charAt(0) == '\\' &&
(((ch = regex.charAt(1))-'0')|('9'-ch)) < 0 &&
((ch-'a')|('z'-ch)) < 0 &&
((ch-'A')|('Z'-ch)) < 0)) &&
(ch < Character.MIN_HIGH_SURROGATE ||
ch > Character.MAX_LOW_SURROGATE))
{
...
}
return Pattern.compile(regex).split(this, limit);
}
if语句判断无法通过,因为不允许使用"."做split的regex字符;第2个条件明显长度只有1;第3个条件ch<55276或者ch>57344才满足。
运行到return语句,Pattern执行结果,获得空数据。
那么只能通过indexOf方法来获得小数位数了:
1位小数且小数第1位是0的(如1.0),显示整数;其他情况显示原小数(String默认会把1.10看成1.1)。
public static String get1BitData(double number) {
String first = String.valueOf(number);
String second = first.substring(first.indexOf("."));
if (second.length() > 1 && !second.endsWith("0")) {
return String.valueOf(number);
}
return String.valueOf((int) number);
}
取相应格式的小数:
-
- System.out.println(new DecimalFormat("0").format(pi));
-
- System.out.println(new DecimalFormat("0.00").format(pi));
-
- System.out.println(new DecimalFormat("00.000").format(pi));
-
- System.out.println(new DecimalFormat("#").format(pi));
-
- System.out.println(new DecimalFormat("#.##%").format(pi));
-
- long c = 299792458;
-
- System.out.println(new DecimalFormat("#.#####E0").format(c));
-
- System.out.println(new DecimalFormat("00.####E0").format(c));
-
- System.out.println(new DecimalFormat(",###").format(c));
-
- System.out.println(new DecimalFormat("光速大小为每秒,###米。").format(c));
Ioc反转和Di注入的可用容器有Spring、JBoss、Ejb等。
它们都是一种编程思想,目的是解耦。
A调用B,正常情况下是,创建B,再调用B,则A依赖B,并且使用完毕还要销毁B。
Ioc,A告诉容器要调用B,容器创建B,并通知A,然后A通过构造函数、属性和接口调用方式,获得B,再去调用B。
Di,A告诉容器要调用B,容器创建B,并通知A,然后A通过反射的方式,获得B,再去调用B。
AOP:Aspect Oriented Programming。面向切面编译,切面指某类的某方法的代码片断,切点(JoinPoint)指某类的某方法。AOP指通过动态注入的方式,将几处共用的代码片断,在使用时注入,使得代码维护更加便利。