栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

2021.09.27

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021.09.27

2021.09.27
  • 存在线程安全的变量及同步锁的使用方式:
  • 处理财务数据的类型:BigDecimal
  • Leetcode经典算法08:排序数组查找元素的第一个位置和最后一个位置
  • Leetcode经典算法09:移除元素不改变下标位置
  • final finally finalize三者的区别
  • 多线程定时器:实现数据定时备份操作

存在线程安全的变量及同步锁的使用方式:
    
	
     */
处理财务数据的类型:BigDecimal
        
        BigDecimal bigDecimal = new BigDecimal(100.1234);
        BigDecimal bigDecimal1 = new BigDecimal(200.1234);
        BigDecimal bigDecimal2 = bigDecimal.add(bigDecimal1);
        System.out.println(bigDecimal2); // 300.24680000000000745785655453801155090332031250
Leetcode经典算法08:排序数组查找元素的第一个位置和最后一个位置
package du;

public class d999 {
    public static void main(String[] args) {
        int[] array = new int[]{1, 1, 2, 3, 3, 4, 5, 6, 6, 7, 7, 8};
        int[] result = searchRange(array, 6);

        for (int i = 0; i < result.length; i++) {
            System.out.println(result[i]);
        }
    }

    
    public static int[] searchRange(int[] array, int target) {
        int[] objects = new int[]{-1, -1};
        if (array.length == 0){
            return objects;
        }
        for (int i = 0; i < array.length; i++) {
            if (array[i] == target) {
                objects[0] = i;
                break;
            }
        }
        for (int j = array.length - 1; j >= 0; j--) {
            if (array[j] == target) {
                objects[1] = j;
                break;
            }
        }
        return objects;
    }
}
Leetcode经典算法09:移除元素不改变下标位置
	
    public int removeElement(int[] nums, int val) {
        if (nums == null || nums.length == 0)
            return 0;
        int j = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                nums[j] = nums[i];
                j++;
            }
        }
        return j;
    }
final finally finalize三者的区别
    
多线程定时器:实现数据定时备份操作
package du;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class d800 {
    public static void main(String[] args) throws Exception {
        
        
        Timer timer = new Timer();
        
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        
        Date firstExecTime = simpleDateFormat.parse("2021-09-27 20:05:00");

        timer.schedule(new LogTimerTask(),firstExecTime,1000*5);
    }
}


class LogTimerTask extends TimerTask {
    @Override
    public void run() {
        
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String string = simpleDateFormat.format(new Date());
        System.out.println(string + "finish data archived");
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/271444.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号