类 CommonUtil
- java.lang.Object
-
- xin.manong.weapon.base.util.CommonUtil
-
public class CommonUtil extends Object
通用工具- 作者:
- frankcl
-
-
构造器概要
构造器 构造器 说明 CommonUtil()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static intcharacterOccurrence(String s, char character)计算字符串中指定字符出现次数static intcomputeGCD(int m, int n)计算最大公约数static intcomputeLCM(int m, int n)计算最小公倍数static StringcomputeLCS(String s1, String s2)计算最长公共子串static StringcomputeLPS(String s)计算最长回文子串static StringcomputeMCS(String s1, String s2)计算最大公共子序列static intfindNextPrime(int n)找到比n大的第一个质数static StringgetHost(String str)获取URL中hoststatic booleanisDigit(char c)判断字符是否为数字static booleanisIP(String str)判断是否为IPstatic booleanisLetter(char c)判断字符是否为字母static booleanisPrime(int n)判断一个整数是否为质数static booleanisPrimitiveType(Object object)判断对象是否为Java原型static booleanisSpace(char c)判断字符是否为空白字符static doubleround(double v, int n)取小数点后n位数字static LongstringToTime(String string, String format)字符串转换时间戳static StringtimeToString(long timestamp, String format)时间戳转换字符串
-
-
-
方法详细资料
-
characterOccurrence
public static int characterOccurrence(String s, char character)
计算字符串中指定字符出现次数- 参数:
s- 字符串character- 字符- 返回:
- 字符出现次数
-
stringToTime
public static Long stringToTime(String string, String format)
字符串转换时间戳- 参数:
string- 时间字符串format- 时间格式,如果为空使用默认格式- 返回:
- 成功返回毫秒时间戳,否则返回null
-
timeToString
public static String timeToString(long timestamp, String format)
时间戳转换字符串- 参数:
timestamp- 毫秒时间戳format- 时间格式- 返回:
- 成功返回字符串表示,否则返回null
-
getHost
public static String getHost(String str)
获取URL中host- 参数:
str- URL字符串- 返回:
- 如果url合法返回host,否则返回空字符串
-
computeLPS
public static String computeLPS(String s)
计算最长回文子串- 参数:
s- 输入字符串- 返回:
- 如果存在返回最大回文子串,否则返回空字符串
-
computeLCS
public static String computeLCS(String s1, String s2)
计算最长公共子串- 参数:
s1- 输入字符串s2- 输入字符串- 返回:
- 如果存在返回公共子串,否则返回空字符串
-
computeMCS
public static String computeMCS(String s1, String s2)
计算最大公共子序列- 参数:
s1- 输入字符串s2- 输入字符串- 返回:
- 如果存在返回最大公共子序列,否则返回空字符串
-
isLetter
public static boolean isLetter(char c)
判断字符是否为字母- 参数:
c- 字符- 返回:
- 如果是字母返回true,否则返回false
-
isDigit
public static boolean isDigit(char c)
判断字符是否为数字- 参数:
c- 字符- 返回:
- 如果是数字返回true,否则返回false
-
isSpace
public static boolean isSpace(char c)
判断字符是否为空白字符- 参数:
c- 字符- 返回:
- 如果是空白字符返回true,否则返回false
-
isIP
public static boolean isIP(String str)
判断是否为IP- 参数:
str- 字符串- 返回:
- 符合IP规范返回true,否则返回false
-
round
public static double round(double v, int n)取小数点后n位数字- 参数:
v- 浮点数n- 小数点后保留位数- 返回:
- 浮点数
-
isPrime
public static boolean isPrime(int n)
判断一个整数是否为质数- 参数:
n- 整数- 返回:
- 质数返回true,否则返回false
-
findNextPrime
public static int findNextPrime(int n)
找到比n大的第一个质数- 参数:
n-- 返回:
- 比n大的第一个质数
-
computeGCD
public static int computeGCD(int m, int n)计算最大公约数- 参数:
m- 输入数字n- 输入数字- 返回:
- 最大公约数
-
computeLCM
public static int computeLCM(int m, int n)计算最小公倍数- 参数:
m- 输入数字n- 输入数字- 返回:
- 最小公倍数
-
isPrimitiveType
public static boolean isPrimitiveType(Object object)
判断对象是否为Java原型- 参数:
object- 对象- 返回:
- 是原型返回true,否则返回false
-
-