简单介绍下今天新用到的知识点:BigDecimal(企业税率,金额计算用到),BigInteger、Lambda类型转换(leetcode刷题遇到的)
总结:
-
BigDecimal用BigDecimal.valueOf或String类型初始化才不会出现精度丢失(BigDecimal内部也有一部分是由BigInteger构成)
-
int[]、List、String[]的转换(主要是靠Lambda,leetcode中二维数组用toArray即可)
-
https://mp.weixin.qq.com/s/H55wlNQkljDyrJfgmLqfKg Linux中命令写的真全
/*BigDecimal、BigInteger与Lambda中类型转换问题*/
package BigDecimal;
import java.math.BigDecimal;
import java.math.BigInteger;
public class Main {
public static void main(String[] args){
System.out.println(new BigDecimal(0.99));
System.out.println(new BigDecimal("0.99"));
System.out.println(BigDecimal.valueOf(0.99));
System.out.println(new BigDecimal(Double.valueOf(0.99)));
System.out.println(new BigDecimal(Double.valueOf(0.99).toString()));
/******BigInteger*******/
BigInteger bigbegin = new BigInteger("13412341");
BigInteger endbegin = new BigInteger("12431");
System.out.println(bigbegin);
/***********************/
/*new BigDecimal()时,尽可能转换为String,或者直接使用BigDecimal.valueof(double)
* */
BigDecimal begin = new BigDecimal(Double.valueOf(123.3));
BigDecimal end = new BigDecimal(Double.valueOf(1233.3));
System.out.println(begin);
System.out.println(end);
System.out.println(begin.add(end).doubleValue());
System.out.println(begin.subtract(end).doubleValue());
System.out.println(begin.multiply(end).doubleValue());
System.out.println(begin.divide(end, 4, BigDecimal.ROUND_HALF_UP).doubleValue());
System.out.println(begin.multiply(new BigDecimal("123")).divide(end, 0, BigDecimal.ROUND_HALF_UP).longValue());
}
}
package lambda;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class typeChange {
public static void main(String[] args){
int[] data = {4, 5, 3, 6, 2, 5, 1};
//int[] 转 List<Integer>
List<Integer> list1 = Arrays.stream(data).boxed().collect(Collectors.toList());
System.out.println("===========" + list1);
//List<Integer> 转 int[]
int[] newData = list1.stream().mapToInt(Integer::valueOf).toArray();
Arrays.stream(newData).forEach(System.out::print);
String[] strings = {"a", "b", "c"};
//String[] 转List<String>
List<String> list2 = Arrays.asList(strings);
System.out.println("===========" + list2);
//List<String>转String[]
String[] string2 = list2.toArray(new String[0]);
Arrays.stream(string2).forEach(System.out::print);
//Leetcode中57-II 二维数组和List的互转
List<int[]> ans = new ArrayList<>();
int[][] ansToInt = ans.toArray(new int[ans.size()][]);
}
}
#查看所有用户信息/组/登录用户名
cat /etc/passwd
groups
whoami
#Shell命令
df
last
w
cal
date
ctrl + L
ctrl + c