Java Tips

1、map.values() 转换成List
Collection<String> valueCollection = map.values();
List<String> valueList = new ArrayList<String>(valueCollection);

2、List元素排序

Collections.sort(timeList, new Comparator<Integer>() {
        @Override
        public int compare(Integer o1, Integer o2) {
            return o1.compareTo(o2);
        }
 });

3、Velocity VM模版加载相对路径设置

<!-- velocity 配置相关属性如VM加载路径-->
    <bean class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
        <property name="velocityProperties">
            <map>
                <entry key="resource.loader" value="class"/>
                <entry key="class.resource.loader.class" value="org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"/>
            </map>
        </property>
    </bean>

4、double保留指定位数

private double truncateFloatNum(double source){
        BigDecimal b = new BigDecimal(source);
        return b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
 }

5、查看crontab message&log

tail -fn 10 /var/log/messages
tail -fn 10 /var/log/cron

6、两个整数相除保留指定位小数

private double divideTwoInteger(int divisor, int dividend){
        double a = divisor;
        double b = dividend;
         if (Double.isInfinite(result) || Double.isNaN(result))
            return 0.0;
        return new BigDecimal(a / b).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
    }




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值