Java 常用工具类

读取properties文件

public static void loadConfiguration()  {
        Properties properties = new Properties();
        BufferedReader bufferedReader = null;
        try {
            bufferedReader = new BufferedReader(new FileReader("src/main/resources/config.properties"));
            properties.load(bufferedReader);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        ConfigConstants.CHROME_PATH = properties.getProperty("chromePath");
        ConfigConstants.SAMPLE_WEIGHT = Integer.parseInt(properties.getProperty("sampleWeight"));
        ConfigConstants.LAST_LENGTH = Integer.parseInt(properties.getProperty("lastLength"));
    }

获取当前日期

   /**
    *
    * @param        dateDifference: 时间偏移,昨天为-1,今天为0
    *               pattern: 样式字符串
    *
    * @return       时间字符串
    *
    * @description   方法描述: 使用日历类,获取当期日期
    *
    * @author       jusang
    *
    * @date         2020/2/28 10:19
    */
    public static String getCurrentDate(int dateDifference, String pattern ){
        Calendar cal= Calendar.getInstance();
        cal.add(Calendar.DATE,dateDifference);
        Date d=cal.getTime();
        SimpleDateFormat sf=new SimpleDateFormat(pattern);
        return sf.format(d);
    }
    
	public static String getDay(){
	    return getCurrentDate(0, "yyyy" + "年" + "MM" + "月" + "dd"+"日");
	}

字符串转拼音


import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

public class PinyinUtil {
    public static String word2PinYin(String word){
        String pinyin = "";
        char[] newChar = word.toCharArray();
        HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
        defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
        defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
        for (int i = 0; i < newChar.length; i++) {
            if (newChar[i] > 128) {
                try {
                    pinyin += PinyinHelper.toHanyuPinyinStringArray(newChar[i], defaultFormat)[0];
                } catch (BadHanyuPinyinOutputFormatCombination e) {
                    e.printStackTrace();
                }
            }else{
                pinyin += newChar[i];
            }
        }
         return  pinyin;
    }

    public static void main(String[] args) {
        str = word2PinYin("天下第一");
        System.out.println(str);
    }
}

中文数字转阿拉伯数字

代码有点长,参考这个链接。可以实现将中文数字转换为阿拉伯数字,以及将一句话中的中文转成阿拉伯数字

hashMap根据数值排序

参考链接

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值