012String +システムクラスクラスクラス+ SimpleDateFromat +日付+カレンダーカテゴリクラスカテゴリ+数学+のBigIntegerクラスとクラスのBigDecimal

A .Stringカテゴリ:Stringオブジェクトのコンストラクタ

定数オブジェクト:二重引用符で囲まれた文字列は、文字列定数を持つオブジェクト。たとえば、次のように「こんにちは」、「12.97」、「少年 」 のように。Unicode文字エンコーディングを使って文字列は、文字は2つのバイトを占めています。

一般的に使用される文字列ベースのコンストラクタ

String s1 = new String();
String s2 = new String(String original);
String s3 = new String(char[] a);
String s4 = new String(char[] a,int startIndex,int count)

注:文字列str = "ABC";区別;と文字列STR1 =新しい文字列( "ABC")?

文字列文字列は、基礎となるチャー[]記憶装置を使用して、不変表す最終あります。

方法

public int length()
public char charAt(int index):返回在指定index位置的字符。index从0开始
public boolean equals(Object anObject):比较两个字符串是否相等。相等返回true。否则返回false
public int compareTo(String anotherString)
public int indexOf(String s):返回s字符串在当前字符串中首次出现的位置。若没有,返回-1
public int indexOf(String s ,int startpoint):返回s字符串从当前字符串startpoint位置开始的,首次出现的位置。
public int lastIndexOf(String s):返回s字符串最后一次在当前字符串中出现的位置。若无,返回-1
public int lastIndexOf(String s ,int startpoint)
public boolean startsWith(String prefix):判断当前字符串是否以prefix开始。
public boolean endsWith(String suffix):判断当前字符串是否以suffix结束。
public boolean regionMatches(int firstStart,String other,int otherStart ,int length): 判断当前字符串从firstStart开始的子串与另一个字符串other从otherStart开始,length长度的字串是否equals
public String substring(int startpoint)
public String substring(int start,int end):返回从start开始到end结束的一个左闭右开的子串。start可以从0开始的。
pubic String replace(char oldChar,char newChar)
public String replaceAll(String old,String new)
public String trim():去除当前字符串中首尾出现的空格,若有多个,就去除多个。
public String concat(String str):连接当前字符串与str
public String[] split(String regex):按照regex将当前字符串拆分,拆分为多个字符串,整体返回值为String[]

変更

文字列 の文字列--->:パッケージ間の基本的なデータ型変換の基本データ型、パッケージ適切なラッパークラスを呼び出すparseXxx(文字列strを)。--->パッケージの基本的なデータ型、文字列をオーバーロードされた文字列を呼び出すのvalueOf()メソッドを。

文字列とバイト間の変換:文字列----> バイト配列文字列の呼び出しGetBytesメソッドを()。バイト配列----> 文字列、文字列のコンストラクタの呼び出し。

文字の文字列と配列の間の変換:文字列----> 文字の配列、文字列を呼び出すtoCharArray()を。文字の配列は----> 文字列はコンストラクタ文字列を呼び出します。

二.StringBuffer クラス

java.lang.StringBuffer変数は文字列を表し、あなたは文字列の内容を追加または削除することができます。文字列の多くの方法と同じですが、StringBufferの変数の長さ。StringBufferのはコンテナです。

方法

添加:append()
删除:delete(int i,int j)
修改:setCharAt(int index,char ch)
查 charAt(int n);
插入:insert(int index,String str) 
反转:reverse()
长度:length()
替换:replace(int startIndex ,int endIndex, String str)
截取:substring(int start,int end)

三.StringBuilderクラス

文字の可変配列は、あるJDK5.0 スレッドセーフ、効率がより高く、新規参入にStringBuffer。

:最後に、高効率のStringBuilde>のStringBuffer>文字列。

四.System クラス

システムにcurrentTimeMillisロング()で提供されたパブリック静的クラスは、1970年1月1日0秒ミリ秒の時間差に0:00現在の時刻を返します。

五、日付クラス

       

@Test
public void test(){
       //创建一个Date的实例
       Date d1 = new Date();
       System.out.println(d1.toString());//Mon May 12 15:17:01 CST 2014
       System.out.println(d1.getTime());//1399879144434
       Date d2 = new Date(1399879144434L);
       System.out.println(d2);//Mon May 12 15:17:01 CST 2014
}

六.SimpleDateFromat クラス

         

@Test
public void test() throws Exception{
       //1.格式化1
       SimpleDateFormat sdf1 = new SimpleDateFormat();
       String date1 = sdf1.format(new Date());
       System.out.println(date1);//14-5-12 下午3:24
       //2.格式化2
       SimpleDateFormat sdf2 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
       date1 = sdf2.format(new Date());
       System.out.println(date1);//星期一, 12 五月 2014 15:29:16 +0800
       
       //3.解析:
       Date date2 = sdf1.parse("14-5-12 下午3:24");
       System.out.println(date2);
       date2 = sdf2.parse("星期一, 12 五月 2014 15:29:16 +0800");
       System.out.println(date2);
}

七.Calendar クラス

              

@Test
//日历:Calendar类   
//方法:get()/add()/set()/Date getTime()/setTime(Date d)
public void test(){
       Calendar c = Calendar.getInstance();
       int day = c.get(Calendar.DAY_OF_MONTH);
       System.out.println(day);
       
       c.add(Calendar.DAY_OF_MONTH, -2);
       day = c.get(Calendar.DAY_OF_MONTH);
       System.out.println(day);
       
       c.set(Calendar.DAY_OF_MONTH, 23);
       Date d = c.getTime();
       System.out.println(d);
}

八の.Math クラス

 

ナイン.BigIntegerのクラスとクラスのBigDecimal

        


@Test
public void testBigInteger() {
       BigInteger bi = new BigInteger("12433241123");
       BigDecimal bd1 = new BigDecimal("12435.351");
       BigDecimal bd2 = new BigDecimal("11");
       System.out.println(bi);;
       System.out.println(bd1.divide(bd2, BigDecimal.ROUND_HALF_UP));
       System.out.println(bd1.divide(bd2, 15, BigDecimal.ROUND_HALF_UP));
}

 

公開された23元の記事 ウォン称賛7 ビュー1654

おすすめ

転載: blog.csdn.net/weixin_44145972/article/details/88926790