zoukankan      html  css  js  c++  java
  • java常用的工具类

     1 包装类
     2 https://www.cnblogs.com/benjieqiang/p/11305777.html
     3 
     4 Arrays类(数组工具类)
     5 package day02.com.offcn.test;
     6 
     7 import java.util.Arrays;
     8 import java.util.List;
     9 
    10 public class 数组 {
    11     public static void main(String[] args) {
    12         //1.生成list
    13         List<Integer> list = Arrays.asList(1,1,1,1);
    14         Integer a[] = {1,23,34,13,23,12,343};
    15 
    16         //2.根据计算索引处左右对象,返回赋值右边
    17         Arrays.parallelPrefix(a, (left, right) -> right);
    18 
    19         //3.数组输出
    20         System.out.println(Arrays.toString(a));
    21 
    22         //4.数组自定义排序,int类型不能实现compatetor接口,因为没有int类型的父类
    23         Arrays.sort(a, (o1, o2) -> o1-o2);
    24 
    25         //5,数组二分查找
    26         int b = Arrays.binarySearch(a, 238);
    27 
    28         //6.数组复制,调用本地方法
    29         //两个数组必须是同一类型,int和integer也不行
    30         int a1[] = {1,23,34,13,23,12,343};
    31         int c[] = new int[10];
    32         System.arraycopy(a1, 0,c, 0 ,a.length);
    33 
    34         //7.数组填充,根据索引
    35         Arrays.parallelSetAll(a1, index -> (int)(Math.random()*10));
    36 
    37         //8.转换为流对象,在转回数组对象
    38         a1 = Arrays.stream(a1).toArray();
    39 
    40     }
    41 }
    42 
    43 
    44 BigDecimal类
    45 public static void main(String[] args) {
    46 
    47         double x = 0.1;
    48         double y = 0.2;
    49 
    50         BigDecimal b1 = new BigDecimal(x+"");
    51         BigDecimal b2 = new BigDecimal(y+"");
    52         BigDecimal b3 = b1.add(b2);
    53 
    54         double result1 = b3.doubleValue();
    55         System.out.println(result1);
    56 
    57         double result2 = b1.subtract(b2).doubleValue();
    58         System.out.println(result2);
    59 
    60         double result3 = b1.multiply(b2).doubleValue();
    61         System.out.println(result3);
    62 
    63         double result4 = b1.divide(b2).doubleValue();
    64         System.out.println(result4);
    65 
    66 }
    67 
    68  Math类和Random类
    69 public class Test04 {
    70    public static void main(String[] args) {
    71        
    72       System.out.println((int)(Math.random()*10));
    73       //随机生成从20到121之间101个数,
    74       Arrays.parallelSetAll(f, operand -> (int)(Math.random()*101+20));
    75       
    76       System.out.println(Math.abs(-9));
    77       System.out.println(Math.cbrt(8));
    78       System.out.println(Math.max(4, 3));
    79       System.out.println(Math.min(4, 3));
    80       System.out.println(Math.round(99.9));
    81       System.out.println(Math.floor(2.2));
    82       System.out.println(Math.ceil(3.4));
    83    }
    84 }
    85 Random random = new Random();
    86 random.nextInt(10)+1;
    87 
    88 System类
    89 gc()
    90 exit()
    91 currentTimeMillis()
    92 arraycopy(Object src, int srcPos, Object dest,int destPos, int length)
    93 int a1[] = {2,2,2,33,23,23,43,4,23,2,32,32,32};
    94 int a2[] = new int[8];
    95 System.arraycopy(a1, 2, a2, 2, 5);
    96 [0, 0, 2, 33, 23, 23, 43, 0]
    我凝视这恒星,等待这那场风暴,我已经准备好了
  • 相关阅读:
    关于maven+springmvc+mybits搭建的框架clean,build后错误:org.apache.ibatis.binding.BindingException的处理
    mvn从下载安装到纯命令行创建第一个mvn程序(编码,编译,测试,安装,打包)全过程细致分解
    C++程序中调用bat
    E2034 Cannot convert 'wchar_t *' to 'const char *' bcb2010
    C++ calling a dll.
    如果你不是为了表现
    cdecl、stdcall、fastcall函数调用约定区别
    桌面便签
    在新的工控机上调试程序注意事项
    listview1.items.itemdata:stream read error
  • 原文地址:https://www.cnblogs.com/cheng5350/p/11488239.html
Copyright © 2011-2022 走看看