java日常问题和技巧1(BigDecimal与int相互转换、判断某元素是否在数组中、求两个List并集、int[]转Integer[])
1.BigDecimal与int相互转换:
1 import java.math.BigDecimal; 2 public class HelloWorld { 3 public static void main(String []args) { 4 //BigDecimal转int 5 BigDecimal bigCount = new BigDecimal("123"); 6 System.out.println(bigCount); 7 int count = bigCount.intValue(); 8 System.out.println(count); 9 //int转BigDecimal 10 int count2 = 456; 11 System.out.println(count2); 12 BigDecimal bigCount2 = new BigDecimal(count2); 13 System.out.println(bigCount2); 14 } 15 }
2.判断某元素是否在数组中
1 public boolean isHave(String[] args, String e) { 2 boolean result = false; 3 return Arrays.asList(args).contains(e); 4 }
这里的List类型是java.util.Arrays$ArrayList
3.求两个List并集
1 public List ListUnion(List list1, List list2) { 2 list1.removeAll(list2); 3 list1.addAll(list2); 4 return list1; 5 }
4.int[]转Integer[]
1 Integer[] integers1 = Arrays.stream(data).boxed().toArray(Integer[]::new);
昔日我曾苍老,如今风华正茂(ง •̀_•́)ง