java-计算map数据的差,包括如何提取map数组的对象get(“key“)

提取对象直接get(“对象的key”)

private static BigDecimal collectNum(List> collect) {
        BigDecimal diffSum = BigDecimal.ZERO;  // 用于存储差值的总和
        for (Map entry : collect) {
            Object startPosObj = entry.get("start_pos");
            Object endPosObj = entry.get("end_pos");

            if (endPosObj != null && startPosObj != null) {
                BigDecimal startPos = new BigDecimal(startPosObj.toString());
                BigDecimal endPos = new BigDecimal(endPosObj.toString());
                BigDecimal diff = endPos.subtract(startPos);
                diffSum = diffSum.add(diff);
            }
        }
        return diffSum;
    }

你可能感兴趣的:(java,服务器,前端)