list分批导⼊db,每1000条数据⼀批,从字符串中获取数字,⼩数,版
本号⽐较
//这个有个弊端: 分组后分批导⼊, 是阻塞的,我没有导⼊完成,别⼈就不能导⼊, 这⾥可以优化成异步,线程池
public static void main(String[] args) {
Random random = new Random();
ArrayList phoneList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
phoneList.add(i);
}
for (int i = 0; i < phoneList.size(); i+=50) {
//每50条数据⼀批
List<Integer> collect = phoneList.stream().skip(i).limit(50).List());
System.out.println(collect.size());
//执⾏⼊库操作
}
}
版本号⽐较
public static boolean isHigherTargetVersion(String sourceVersion, String targetVersion){
if("".im()) || null == sourceVersion){
return Boolean.FALSE;
}
if("".im()) || null == targetVersion){
return Boolean.TRUE;
}
String[] sourceVersionSplit = sourceVersion.split("\\.");
String[] targetVersionSplit = targetVersion.split("\\.");
int minlenhgt = sourceVersionSplit.length > targetVersionSplit.length ? targetVersionSplit.length : sourceVersionSplit.length;
for(int i = 0;i < minlenhgt; i++){
Integer sourceTempVersion = Integer.parseInt(sourceVersionSplit[i]);
Integer targetTempVersion = Integer.parseInt(targetVersionSplit[i]);
if(sourceTempVersion.intValue() == targetTempVersion.intValue()){
continue;
}
return sourceTempVersion > targetTempVersion;
}
return sourceVersionSplit.length >= targetVersionSplit.length;
}
// 从字符串中获取数字
public static String stringFormatNumber(String str){
String regEx="[^0-9]";
Pattern p = Patternpile(regEx);
Matcher m = p.matcher(str);
placeAll("").trim();
}
public static String getNumber(String str){
// 控制正则表达式的匹配⾏为的参数(⼩数)
Pattern p = Patternpile("(\\d+\\.\\d+)");
//Matcher类的构造⽅法也是私有的,不能随意创建,只能通过Pattern.matcher(CharSequence input)⽅法得到该类的实例.
Matcher m = p.matcher(str);
//m.find⽤来判断该字符串中是否含有与"(\\d+\\.\\d+)"相匹配的⼦串
if (m.find()) {
//如果有相匹配的,则判断是否为null操作
//group()中的参数:0表⽰匹配整个正则,1表⽰匹配第⼀个括号的正则,2表⽰匹配第⼆个正则,在这只有⼀个括号,即1和0是⼀样的
str = m.group(1) == null ? "" : m.group(1);
} else {
//如果匹配不到⼩数,就进⾏整数匹配
p = Patternpile("(\\d+)");
m = p.matcher(str);
if (m.find()) {
//如果有整数相匹配
str = m.group(1) == null ? "" : m.group(1);
} else {
//如果没有⼩数和整数相匹配,即字符串中没有整数和⼩数,就设为空
str = "";
}
}
return str;
}
/**
* 版本号⽐较
*
* @param v1
* @param v2
* @return 0代表相等,1代表左边⼤,-1代表右边⼤
* UtilspareVersion("1.0.358_20180820090554","1.0.358_20180820090553")=1 */
public static int compareVersion(String v1, String v2) {
formatnumber数字格式
if (v1.equals(v2)) {
return 0;
}
String[] version1Array = v1.split("[._]");
String[] version2Array = v2.split("[._]");
int index = 0;
int minLen = Math.min(version1Array.length, version2Array.length);
long diff = 0;
while (index < minLen
&& (diff = Long.parseLong(version1Array[index])
- Long.parseLong(version2Array[index])) == 0) {
index++;
}
if (diff == 0) {
for (int i = index; i < version1Array.length; i++) {
if (Long.parseLong(version1Array[i]) > 0) {
return 1;
}
}
for (int i = index; i < version2Array.length; i++) {
if (Long.parseLong(version2Array[i]) > 0) {
return -1;
}
}
return 0;
} else {
return diff > 0 ? 1 : -1;
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论