Java版本:1.8开始 import java.time.LocalDate; import java.time.LocalDateTime; /** * Created by Frank */ public class DateParse { public static void main(String[] args) { String armisticeDate = "1914-11-11"; LocalDate alD = LocalDate.parse(armisticeDa…
使用for循环和String对象的charAt()方法:或者,使用"for each"循环和String对象的toCharArray()方法. /** * Created by Frank */ public class StrCharAt { public static void main(String[] args) { String a = "A quick bronze fox lept a lazy bovine"; for (int i = 0; i &…
使用StringBuilder类的reverse()方法来实现. /** * Created by Frank */ public class StringRevChar { public static void main(String[] args) { String sh = "ABCDEFG"; System.out.println(sh + "->" + new StringBuilder(sh).reverse()); } }…
import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Created by Frank */ public class REMatch { public static void main(String[] args) { String patt = "Q[^u]\\d+\\."; Pattern r = Pattern.compile(patt); String line = "Order…
import java.util.regex.Pattern; /** * Created by Frank * 在Java中使用正则表达式:测试模式 */ public class RESimple { public static void main(String[] args) { String pattern = "^Q[^u]\\d+\\."; String[] input = {"QA777. is the next flight. It is on time.&q…
Java版本:1.8开始 import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; /** * Created by Frank */ public class CurrentDatetime { public static void main(String[] args) { // 纪元秒和本地日期时间互换 Instant epochSec = Instant.ofEpochSecond…