文章目录
- 1、String
- 1)String内存解析
- 2)String的使用
- 3)String实例化
- 4)图解两种创建字符串方式的区别
- 5)图解字符串的存储
- 6)图解字符串对象的存储
- 7)String不同拼接操作的对比:
-
- 8)String的常用方法
- 9)String和其他类型之间的转换
- 10)String的五道面试题
- 2、String、StringBuffer和StringBuilder的使用
-
- 3、时间日期类
- 1)jdk8之前的时间日期API
- ①时间戳
- ②java.util.Date
- ③java.sql.Date
- ④SimpleDateFormat类
- 练习一:字符串2020-09-08转换为java.sql.Date
- 练习二:渔夫三天打鱼,两天晒网。1990-01-01
- ⑤Calendar日历类的使用(抽象类)
- 2)jdk8以后时间日期API
- ①LocalDate,LocalTime,LocalDateTime的使用
- ②Instant类
- ③DateTimeFormatter类
- ④其他API
- 4、比较器与其他类
- 1)比较器
- 2) System类
- 3)Math类
- 4)BigInteger和BigDecimal
文章 | 链接 |
---|
Java语法 | https://blog.csdn.net/weixin_45606067/article/details/107049186 |
一维数组与二维数组、内存解析 | https://blog.csdn.net/weixin_45606067/article/details/107049178 |
面向对象(1/3)类和对象 | https://blog.csdn.net/weixin_45606067/article/details/108234276 |
面向对象(2/3)封装性、继承性、多态性 | https://blog.csdn.net/weixin_45606067/article/details/108234328 |
面向对象(3/3)抽象类、接口、内部类、代码块 | https://blog.csdn.net/weixin_45606067/article/details/108258152 |
异常处理 | 待更新 |
多线程(1/2) | https://blog.csdn.net/weixin_45606067/article/details/107067785 |
多线程(2/2) | https://blog.csdn.net/weixin_45606067/article/details/107067857 |
常用类 | https://blog.csdn.net/weixin_45606067/article/details/108283203 |
枚举与注解 | 待更新 |
集合(1/5)Collection、Iterator、增强for | https://blog.csdn.net/weixin_45606067/article/details/107046876 |
集合(2/5)List、ArrayList、LinkedList、Vector的底层源码 | https://blog.csdn.net/weixin_45606067/article/details/107069742 |
集合(3/5)set、HashSet、LinkedHashSet、TreeSet的底层源码 | |
集合(4/5)Map、HashMap底层原理分析 | https://blog.csdn.net/weixin_45606067/article/details/107042949 |
集合(5/5)LinkHashMap、TreeMap、Properties、Collections工具类 | https://blog.csdn.net/weixin_45606067/article/details/107069691 |
泛型与File | https://blog.csdn.net/weixin_45606067/article/details/107124099 |
IO流与网络编程 | https://blog.csdn.net/weixin_45606067/article/details/107143670 |
反射机制 | 待更新 |
Java8新特性 | https://blog.csdn.net/weixin_45606067/article/details/107280823 |
Java9/10/11新特性 | 待更新 |
1、String
1)String内存解析
2)String的使用
@Test
public void test1(){
String s1 = "abc";
String s2 = "abc";
System.out.println(s1 == s2);
System.out.println(s1);
System.out.println(s2);
System.out.println("****************");
String s3 = "abc";
s3 += "def";
System.out.println(s3);
System.out.println(s2);
System.out.println("****************");
String s4 = "abc";
String s5 = s4.replace('a','m');
System.out.println(s4);
System.out.println(s5);
}
3)String实例化
@Test
public void test2(){
String s1 = "JavaEE";
String s2 = "JavaEE";
String s3 = new String("JavaEE");
String s4 = new String("JavaEE");
System.out.println(s1 == s2);
System.out.println(s1 == s3);
System.out.println(s1 == s4);
System.out.println(s3 == s4);
System.out.println("*******************");
Person p1 = new Person("Tom",12);
Person p2 = new Person("Tom",12);
System.out.println(p1.name.equals(p2.name));
System.out.println(p1.name == p2.name);
p1.name = "Jerry";
System.out.println(p2.name);
}
4)图解两种创建字符串方式的区别
5)图解字符串的存储
6)图解字符串对象的存储
7)String不同拼接操作的对比:
@Test
public void test3(){
String s1="javaEE";
String s2="hadoop";
String s3="javaEEhadoop";
String s4="javaEE" + "hadoop";
String s5 = s1 + "hadoop";
String s6 = "javaEE" + s2;
String s7 = s1 + s2;
String s8 = s5.intern();
final String s9 = "javaEE";
String s10 = s9 + "hadoop";
System.out.println(s3==s4);
System.out.println(s4==s5);
System.out.println(s3==s5);
System.out.println(s5==s6);
System.out.println(s3==s7);
System.out.println(s5==s7);
System.out.println(s6==s7);
System.out.println(s8==s3);
System.out.println(s10==s3);
}
面试题
public class StringTest {
String str = new String("good");
char[] ch = { 't', 'e', 's', 't' };
public void change(String str, char ch[]) {
str = "test ok";
ch[0] = 'b';
}
public static void main(String[] args) {
StringTest ex = new StringTest();
ex.change(ex.str, ex.ch);
System.out.print(ex.str + " and ");
System.out.println(ex.ch);
}
}
8)String的常用方法
public class StringMethodTest {
@Test
public void test1(){
String s1 = "HelloWorld";
System.out.println(s1.length());
System.out.println(s1.charAt(9));
System.out.println(s1.isEmpty());
System.out.println(s1.toLowerCase());
String s2 = " he ll o wor ld ";
System.out.println("-"+s2+"-");
System.out.println("-"+s2.trim()+"-");
String s3 = "helloworld";
System.out.println(s3.equals(s1));
System.out.println(s3.equalsIgnoreCase(s1));
String s4 = "efg";
System.out.println(s3.concat(s4));
String s5 = "abc";
String s6 = "abe";
System.out.println(s5.compareTo(s6));
System.out.println(s3.substring(5));
System.out.println(s3.substring(2,6));
}
}
@Test
public void test2(){
String str1 = "helloworld";
boolean b1 = str1.endsWith("ld");
System.out.println(b1);
boolean b2 = str1.startsWith("He");
System.out.println(b2);
boolean b3 = str1.startsWith("ll", 2);
System.out.println(b3);
String str2 = "wo";
System.out.println(str1.contains(str2));
System.out.println(str1.indexOf("lo"));
System.out.println(str1.indexOf("lol"));
System.out.println(str1.indexOf("lo",5));
String str3 = "hellorworld";
System.out.println(str3.lastIndexOf("or"));
System.out.println(str3.lastIndexOf("or",6));
}
@Test
public void test3(){
String str3 ="北京尚硅谷教育北京";
System.out.println(str3.replace('北','东'));
String str = "12hello34world5java7891mysql456";
String string = str.replaceAll("\\d+", ",").replaceAll("^,|,$", "");
System.out.println(string);
str = "12345";
boolean matches = str.matches("\\d+");
System.out.println(matches);
String tel = "0571-4534289";
boolean result = tel.matches("0571-\\d{7,8}");
System.out.println(result);
str = "hello|world|java";
String[] strs = str.split("\\|");
for (int i = 0; i < strs.length; i++) {
System.out.println(strs[i]);
}
System.out.println();
String str2 = "hello.world.java";
String[] strs2 = str2.split("\\.");
for (int i = 0; i < strs2.length; i++) {
System.out.println(strs2[i]);
}
}
9)String和其他类型之间的转换
@Test
public void test1(){
String str1 = "123";
int num = Integer.parseInt(str1);
String str2 = String.valueOf(num);
String str7 = num + "";
}
@Test
public void test2(){
String str1 = "abc123";
char[] charArray = str1.toCharArray();
for (int i = 0; i < charArray.length; i++) {
System.out.println(charArray[i]);
}
char[] arr = new char[]{'h','e','1','1','o'};
String str2 = new String(arr);
System.out.println(str2);
}
@Test
public void test3() throws UnsupportedEncodingException {
String str1 = "abc123中国";
byte[] bytes = str1.getBytes();
System.out.println(Arrays.toString(bytes));
byte[] gbks = str1.getBytes("gbk");
System.out.println(Arrays.toString(gbks));
String str6 = new String(bytes);
System.out.println(str6);
String str3 = new String(gbks);
System.out.println(str3);
String str4 = new String(gbks,"gbk");
System. out. println(str4);
}
10)String的五道面试题
public String myTrim(String str) {
if (str != null) {
int start = 0;
int end = str.length() - 1;
while (start < end && str.charAt(start) == ' ') {
start++;
}
while (start < end && str.charAt(end) == ' ') {
end--;
}
if (str.charAt(start) == ' ') {
return "";
}
return str.substring(start, end + 1);
}
return null;
}
@Test
public void testMyTrim() {
String str = " abcdef ";
String newStr = myTrim(str);
System.out.println("---" + newStr + "---");
}
public String reverse(String str, int startIndex, int endIndex){
if (str != null && str.length() != 0){
char[] arr = str.toCharArray();
for (int x = startIndex, y = endIndex; x < y; x++, y--) {
char temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
return new String(arr);
}
return null;
}
public String reverse1(String str, int startIndex, int endIndex) {
if (str != null) {
String reverseStr = str.substring(0,startIndex);
for (int i = endIndex; i >= startIndex; i--) {
reverseStr += str.charAt(i);
}
reverseStr += str.substring(endIndex + 1);
return reverseStr;
}
return null;
}
public String reverse2(String str, int startIndex, int endIndex) {
if (str != null){
StringBuilder builder = new StringBuilder(str.length());
builder.append(str.substring(0, startIndex));
for (int i = endIndex; i >= startIndex; i--) {
builder.append(str.charAt(i));
}
builder.append(str.substring(endIndex + 1));
return builder.toString();
}
return null;
}
@Test
public void testReverse(){
String str = "abcdefg";
String reverse = reverse2(str, 2, 5);
System.out.println(reverse);
}
public int getCount(String mainStr,String subStr){
int mainLength = mainStr.length();
int subLength = subStr.length();
int count = 0;
int index = 0;
if (mainLength >= subLength){
while ((index = mainStr.indexOf(subStr, index)) != -1) {
count++;
index += subLength;
}
return count;
}else{
return 0;
}
}
@Test
public void testGetCount(){
String mainStr = "cdabkkcadkabkebfkaabkskab";
String subStr = "ab";
int count = getCount(mainStr, subStr);
System.out.println(count);
}
public String getMaxSameString(String str1, String str2){
if (str1 != null && str2 != null) {
String maxStr = (str1.length() > str2.length()) ? str1 : str2;
String minStr = (str1.length() > str2.length()) ? str2 : str1;
int len = minStr.length();
for (int i = 0; i < len; i++) {
for (int x = 0, y = len - i; y <= len; x++, y++) {
String subStr = minStr.substring(x, y);
if (maxStr.contains(subStr)) {
return subStr;
}
}
}
}
return null;
}
public String[] getMaxSameString1(String str1, String str2) {
if (str1 != null && str2 != null) {
StringBuffer sBuffer = new StringBuffer();
String maxString = (str1.length() > str2.length()) ? str1 : str2;
String minString = (str1.length() > str2.length()) ? str2 : str1;
int len = minString.length();
for (int i = 0; i < len; i++) {
for (int x = 0, y = len - i; y <= len; x++, y++) {
String subString = minString.substring(x, y);
if (maxString.contains(subString)) {
sBuffer.append(subString + ",");
}
}
if (sBuffer.length() != 0) {
break;
}
}
String[] split = sBuffer.toString().replaceAll(",$", "").split("\\,");
return split;
}
return null;
}
public List<String> getMaxSameString2(String str1, String str2) {
if (str1 != null && str2 != null) {
List<String> list = new ArrayList<String>();
String maxString = (str1.length() > str2.length()) ? str1 : str2;
String minString = (str1.length() > str2.length()) ? str2 : str1;
int len = minString.length();
for (int i = 0; i < len; i++) {
for (int x = 0, y = len - i; y <= len; x++, y++) {
String subString = minString.substring(x, y);
if (maxString.contains(subString)) {
list.add(subString);
}
}
if (list.size() != 0) {
break;
}
}
return list;
}
return null;
}
@Test
public void testGetMaxSameSubString() {
String str1 = "abcwerthelloyuiodef";
String str2 = "cvhellobnmiodef";
String str = getMaxSameString(str1, str2);
System.out.println(str);
String[] strs = getMaxSameString1(str1, str2);
System.out.println(Arrays.toString(strs));
List<String> strList = getMaxSameString2(str1, str2);
System.out.println(strList);
}
@Test
public void testSort() {
String str = "abcwerthelloyuiodef";
char[] arr = str.toCharArray();
Arrays.sort(arr);
String newStr = new String(arr);
System.out.println(newStr);
}
2、String、StringBuffer和StringBuilder的使用
@Test
public void test2(){
StringBuffer s1 = new StringBuffer("abc");
s1.append(2);
s1.append('e');
String s2 = s1.substring(1, 4);
s1.length();
}
@Test
public void test1(){
StringBuffer sb1 = new StringBuffer("abc") ;
sb1.setCharAt(0, 'm' );
System.out.println(sb1);
StringBuffer sb2 = new StringBuffer() ;
System.out.println(sb2.length());
}
三者的效率比较
@Test
public void test3(){
long startTime = 0L;
long endTime = 0L;
String text = "";
StringBuffer buffer = new StringBuffer("");
StringBuilder builder = new StringBuilder("");
startTime = System.currentTimeMillis();
for (int i = 0; i < 20000; i++) {
buffer.append(String.valueOf(i));
}
endTime = System.currentTimeMillis();
System.out.println("StringBuffer的执行时间:" + (endTime - startTime));
startTime = System.currentTimeMillis();
for (int i = 0; i < 20000; i++) {
builder.append(String.valueOf(i));
}
endTime = System.currentTimeMillis();
System.out.println("StringBuilder的执行时间:" + (endTime - startTime));
startTime = System.currentTimeMillis();
for (int i = 0; i < 20000; i++) {
text = text + i;
}
endTime = System.currentTimeMillis();
System.out.println("String的执行时间:" + (endTime - startTime));
}
面试题
public static void main(String[] args) {
String s1=null;
StringBuffer sb1=new StringBuffer();
sb1.append(s1);
System.out.println(sb1.length());
System.out.println(sb1);
StringBuffer sb2=new StringBuffer(s1);
System.out.println(sb2);
}
3、时间日期类
1)jdk8之前的时间日期API
①时间戳
@Test
public void test1(){
long time = System.currentTimeMillis();
System.out.println(time);
}
②java.util.Date
@Test
public void test2(){
Date date1 = new Date();
System.out.println(date1.toString());
System.out.println(date1.getTime());
Date date2 = new Date(1550306204104L);
System.out.println(date2.toString());
java.sql.Date date3 = new java.sql.Date(1550306204104L);
System.out.println(date3);
}
③java.sql.Date
@Test
public void test3(){
Date date6 = new Date();
java.sql.Date date7 = new java.sql.Date(date6.getTime());
}
④SimpleDateFormat类
@Test
public void testSimpleDateFormat() throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat();
Date date = new Date();
System.out.println(date);
String format = sdf.format(date);
System.out.println(format);
String str ="20-6-26 下午5:06";
Date date1 = sdf.parse(str);
System.out.println(date1);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String format1 = simpleDateFormat.format(date);
System.out.println(format1);
Date date2 = simpleDateFormat.parse("2020-06-26 05:10:46");
System.out.println(date2);
}
练习一:字符串2020-09-08转换为java.sql.Date
@Test
public void testExer() throws ParseException {
String birthday = "2020-06-26";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(birthday);
System.out.println(date);
java.sql.Date birDate = new java.sql.Date(date.getTime());
System.out.println(birDate);
}
练习二:渔夫三天打鱼,两天晒网。1990-01-01
@Test
public void testExer1() throws ParseException {
String start = "1990-01-01";
String end = "2020-09-08";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date dateStart = simpleDateFormat.parse(start);
Date dateEnd = simpleDateFormat.parse(end);
long dateStartTime = dateStart.getTime();
long dateEndTime = dateEnd.getTime();
long date = (dateEndTime - dateStartTime) / (1000 * 60 * 60 * 24) + 1;
if (date %5 ==4 && date %5 ==0){
System.out.println("晒网");
}else{
System.out.println("打渔");
}
}
⑤Calendar日历类的使用(抽象类)
@Test
public void testCalendar(){
Calendar calendar =Calendar.getInstance();
System.out.println(calendar.getClass());
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
calendar.set(Calendar.DAY_OF_MONTH, 22);
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
calendar.add(Calendar.DAY_OF_MONTH,3);
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
System.out.println(calendar.getTime());
calendar.setTime(new Date());
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
}
2)jdk8以后时间日期API
前两代存在的问题举例:
可变性:像日期和时间这样的类应该是不可变的。
倡多性: Date中 的年份是从1900开始的,而月份都从0开始。
格式化:格式化只对Date用,Calendar则不行。
此外,它们也不是线程安全的;不能处理国秒等。
①LocalDate,LocalTime,LocalDateTime的使用
@Test
public void test() {
LocalDate now = LocalDate.now();
LocalTime now1 = LocalTime.now();
LocalDateTime now2 = LocalDateTime.now();
System.out.println(now);
System.out.println(now1);
System.out.println(now2);
}
@Test
public void test2() {
LocalDate date = LocalDate.of(2020, 6, 27);
System.out.println(date);
}
@Test
public void test3() {
LocalDateTime time = LocalDateTime.of(2012, 6, 26, 17, 49, 23);
System.out.println(time.getDayOfMonth());
System.out.println(time.getDayOfWeek());
System.out.println(time.getDayOfYear());
System.out.println(time.getHour());
System.out.println(time.getMonthValue());
}
@Test
public void test4() {
LocalDateTime time = LocalDateTime.of(2012, 6, 26, 17, 49, 23);
LocalDateTime localDateTime = time.withDayOfMonth(2);
System.out.println(localDateTime);
LocalDateTime plusDays = time.plusDays(108);
System.out.println(plusDays);
LocalDateTime minusDays = time.minusDays(20);
System.out.println(minusDays);
}
②Instant类
@Test
public void test5(){
Instant instant = Instant.now();
System.out.println(instant);
OffsetDateTime offsetDateTime = instant.atOffset(ZoneOffset.ofHours(8));
System.out.println(offsetDateTime);
long second = offsetDateTime.toEpochSecond();
System.out.println(second);
Instant instant1 = Instant.ofEpochMilli(1590495314878L);
System.out.println(instant1);
}
③DateTimeFormatter类
@Test
public void test6(){
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
LocalDateTime localDateTime = LocalDateTime.now();
String format = formatter.format(localDateTime);
System.out.println(localDateTime);
System.out.println(format);
TemporalAccessor parse = formatter.parse("2020-06-26T20:28:53.058");
System.out.println(parse);
DateTimeFormatter formatter1 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
String format1 = formatter1.format(localDateTime);
System.out.println(format1);
DateTimeFormatter formatter2 = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
String format2 = formatter2.format(LocalDate.now());
System.out.println(format2);
DateTimeFormatter formatter3 = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
String format3 = formatter3.format(LocalDateTime.now());
System.out.println(format3);
TemporalAccessor parse1 = formatter3.parse("2020-06-26 08:46:55");
System.out.println(parse1);
}
④其他API
@Test
public void test7(){
Set<String> zoneIds = ZoneId.getAvailableZoneIds();
for (String s : zoneIds) {
System.out.println(s);
}
LocalDateTime localDateTime = LocalDateTime.now(ZoneId.of("Asia/Tokyo"));
System.out.println(localDateTime);
ZonedDateTime zonedDateTime = ZonedDateTime.now();
System.out.println(zonedDateTime);
ZonedDateTime zonedDateTime1 = ZonedDateTime.now(ZoneId.of("Asia/Tokyo"));
System.out.println(zonedDateTime1);
LocalTime localTime = LocalTime.now();
LocalTime localTime1 = LocalTime.of(15, 23, 32);
Duration duration = Duration.between(localTime1, localTime);
System.out.println(duration);
System.out.println(duration.getSeconds());
System.out.println(duration.getNano());
LocalDateTime localDateTime1 = LocalDateTime.of(2016, 6, 12, 15, 23, 32);
LocalDateTime localDateTime2 = LocalDateTime.of(2017, 6, 12, 15, 23, 32);
Duration duration1 = Duration.between(localDateTime2, localDateTime1);
System.out.println(duration1.toDays());
LocalDate localDate = LocalDate.now();
LocalDate localDate1 = LocalDate.of(2028, 3, 18);
Period period = Period.between(localDate, localDate1);
System.out.println(period);
System.out.println(period.getYears());
System.out.println(period.getMonths());
System.out.println(period.getDays());
Period period1 = period.withYears(2);
System.out.println(period1);
TemporalAdjuster temporalAdjuster = TemporalAdjusters.next(DayOfWeek.SUNDAY);
LocalDateTime localDateTime3 = LocalDateTime.now().with(temporalAdjuster);
System.out.println(localDateTime3);
LocalDate localDate2 = LocalDate.now().with(new TemporalAdjuster() {
@Override
public Temporal adjustInto(Temporal temporal) {
LocalDate date = (LocalDate) temporal;
if (date.getDayOfWeek().equals(DayOfWeek.FRIDAY)) {
return date.plusDays(3);
} else if (date.getDayOfWeek().equals(DayOfWeek.SATURDAY)) {
return date.plusDays(2);
} else {
return date.plusDays(1);
}
}
});
System.out.println("下一个工作日是:" + localDate2);
}
4、比较器与其他类
1)比较器
public class CompareTest {
@Test
public void test1(){
String[] arr = new String[]{"AA","KK","DD","GG","MM","JJ","DD"};
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
}
@Test
public void test2(){
Goods[] arr = new Goods[5];
arr[0]=new Goods("lenovo",50.0);
arr[1]=new Goods("honor",35.0);
arr[2]=new Goods("iphone",888.8);
arr[3]=new Goods("lenovo",66.6);
arr[4]=new Goods("apple",66.6);
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
}
@Test
public void test3(){
String[] arr = new String[]{"AA","KK","DD","GG","MM","JJ","DD"};
Arrays.sort(arr, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
if (o1 instanceof String && o2 instanceof String){
String s1 = (String) o1;
String s2 = (String) o2;
return -s1.compareTo(s2);
}
throw new RuntimeException("传入的数据类型不一致");
}
});
System.out.println(Arrays.toString(arr));
}
@Test
public void test4(){
Goods[] arr = new Goods[6];
arr[0]=new Goods("lenovo",50.0);
arr[1]=new Goods("honor",35.0);
arr[2]=new Goods("iphone",888.8);
arr[3]=new Goods("lenovo",66.6);
arr[4]=new Goods("sapple",66.6);
arr[5]=new Goods("sanxing",78.6);
Arrays.sort(arr, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
if (o1 instanceof Goods && o2 instanceof Goods){
Goods g1 = (Goods) o1;
Goods g2 = (Goods) o2;
if (g1.getName().equals(g2.getName())){
return -Double.compare(g1.getPrice(),g2.getPrice());
}else{
return g1.getName().compareTo(g2.getName());
}
}
throw new RuntimeException("传入的数据类型不一致");
}
});
System.out.println(Arrays.toString(arr));
}
}
public class Goods implements Comparable{
private String name;
private double price;
@Override
public int compareTo(Object o) {
if (o instanceof Goods){
Goods goods = (Goods) o;
if (this.price > goods.price){
return 1;
}else if (this.price < goods.price){
return -1;
}else {
return this.name.compareTo(goods.name);
}
}else{
throw new RuntimeException("传入的数据类型不一致!");
}
}
}
2) System类
@Test
public void test1(){
String javaVersion = System.getProperty("java.version");
System.out.println("java的version:" + javaVersion);
String javaHome = System.getProperty("java.home");
System.out.println("java的home:" + javaHome);
String osName = System.getProperty("os.name");
System.out.println("os的name:" + osName);
String osVersion = System.getProperty("os.version");
System.out.println("os的version:" + osVersion);
String userName = System.getProperty("user.name");
System.out.println("user的name:" + userName);
String userHome = System.getProperty("user.home");
System.out.println("user的home:" + userHome);
String userDir = System.getProperty("user.dir");
System.out.println("user的dir:" + userDir);
}
3)Math类
4)BigInteger和BigDecimal
高精度整数运算器和高精度浮点数运算器
如果有收获!!! 希望老铁们来个三连,点赞、收藏、转发。
创作不易,别忘点个赞,可以让更多的人看到这篇文章,顺便鼓励我写出更好的博客
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)