统计某个字符在字符串中出现的次数
public int Charcount(String string, String str) {
int ii = 0;
if (string == null)
return 0;
int[] count = new int[string.length()];
// 将字符串中索引字符存在临时变量中
char mid = str.charAt(0);
for (int j = 0; j < count.length; j++) {
char temp = string.charAt(j);
if (mid == temp)
ii++;
}
return ii;
}
时间字符串的比较
public static int compare_date(String DATE1, String DATE2) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
try {
Date dt1 = df.parse(DATE1);
Date dt2 = df.parse(DATE2);
if (dt1.getTime() > dt2.getTime()) {
System.out.println("dt1 在dt2后");
return 1;
} else if (dt1.getTime() < dt2.getTime()) {
System.out.println("dt1在dt2前");
return -1;
} else {
return 0;
}
} catch (Exception exception) {
exception.printStackTrace();
}
return 0;
}
public static void main(String args[]) {
int i= compare_date("1995-11-12 15:21", "1999-12-11 09:59");
System.out.println("i=="+i);
} |