后端常用api

IO

byte[] bytes=Files.readAllBytes(File fle):将文件返回字节数组

Paths.get(path):通过知道文件路径,返回文件

String path = "C:\\Users\\ThinkPad\\Desktop\\ihrm\\day11\\资源\\照片\\001.png";
byte[] bytes = Files.readAllBytes(Paths.get(path));
String image = Base64Util.encode(bytes);

 

Map

map.computeIfAbsent()

1、首先会判断map中是否有对应的Key

2.1、如果没有对应的Key,则会创建一个满足Value类型的数据结构放到Value的位置中;

2.2、如果有对应的Key,则会操作该Key对应的Value.

  public static void main(String[] args) {
        HashMap<String, List<Integer>> map = new HashMap<>();
        /**
         * 首先,Map中没有 "hadoop" 这个Key,所以会创建一个满足Value类型的数据结构放入到Key对应的Value中
         * 随后对该Value对应的值进行操作,如下代码是:list.add(1)
         */
        map.computeIfAbsent("hadoop", key -> new ArrayList<>()).add(1);
        System.out.println(map);//{hadoop=[1]}

        /**
         * Map中已经有 "hadoop" 这个 Key,所以会操作该Key对应的一个Value
         * 如下代码,对Key对应的Value进行 list.add(2) 这个操作
         */
        map.computeIfAbsent("hadoop", key -> new ArrayList<>()).add(2);
        System.out.println(map);//{hadoop=[1, 2]}

    }

Double.IntValue()方法可以将double转换为int 。

public class Main{
     public static void main(String []args){
        double doubleValue = 82.14; // 82.14
        Double doubleValueObject = new Double(doubleValue);
        int intValue = doubleValueObject.intValue(); // 82
     }
}

DecimalFormat:用于格式化十进制数字

    DecimalFormat df1 = new DecimalFormat("0.0"); 
    DecimalFormat df2 = new DecimalFormat("#.#"); 
    DecimalFormat df3 = new DecimalFormat("000.000"); 
    DecimalFormat df4 = new DecimalFormat("###.###"); 
    System.out.println(df1.format(12.34)); //12.3  
    System.out.println(df2.format(12.34)); //12.3  
    System.out.println(df3.format(12.34)); //012.340  
    System.out.println(df4.format(12.34)); //12.34   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LI JS@你猜啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值