String, stringbuffer,Integer,Double的方法简单使用
package com.fanjia.practice;
import org.junit.Test;
/**
* Created by FanJia on 2020/8/16 8:12
*/
public class Demo01 {
@Test
public void test(){
String s = new String("aaa");
String s1 = "hello";
int length = s1.length();
System.out.println(length);
System.out.println(s1.charAt(1));
System.out.println(s1.lastIndexOf("l"));
String s2 = "abc";
String s3 = "def";
String s4 = "abcdef";
String s5 = s2+s3;
String s6 = "abcdef";
if(s4.equals(s5) ){
System.out.println(true);
}else {
System.out.println(false);
}
if(s6.equals(s4)){
System.out.println(true);
}else{
System.out.println(false);
}
}
@Test
public void test2(){
String s = "hello";
System.out.println(s.substring(3, 5));
System.out.println(s.equals("hello"));
System.out.println(s.startsWith("f"));
System.out.println(s.endsWith("l"));
String[] ls = s.split("l");
for(String a : ls){
System.out.println(a);
}
String s1 = " abcdefaf ";
System.out.println(s1.trim());
}
//StringBuilder
//stringBuffer
@Test
public void test3(){
StringBuffer sb = new StringBuffer("abcd");
StringBuffer sb2 = new StringBuffer("efg");
StringBuffer append = sb.append(sb2);
System.out.println(append);
System.out.println(sb.charAt(2));
}
//Integer
@Test
public void test4(){
//Integer a = new Integer(5);
Integer i2 = Integer.valueOf(5);
System.out.println(i2);
int i = Integer.parseInt("15");
System.out.println(i+3);
System.out.println(Integer.toBinaryString(10));
System.out.println(Integer.toOctalString(16));
String s = Integer.toHexString(17);
System.out.println(s);
}
//Double
@Test
public void test5(){
Double d1 = new Double(3.14);
Double b2 = Double.valueOf(3.14);
System.out.println(Double.parseDouble("3.114"));
}
}