8.1.String類html
String s = new String("we are students");
java
String tom = new String(s);
git
Syste.out.println(s);
輸出的是對象的實體,即字符序列we are students
。正則表達式
1.public int length()
:獲取一個字符串的長度數組
2.public boolean equals(String s)
:判斷當前String對象的字符序列是否與參數s指定的String對象的字符序列相同app
3.public boolean startsWith(String s)
判斷當前String對象的字符序列前綴是不是參數指定的String對象s的字符序列,例如:dom
String tom = "天氣預報,陰有小雨",jerry = "比賽結果,中國隊贏得勝利";
學習
tom.startsWith(「天氣」)的值是true;設計
tom.endsWith("大雨")的值是false3d
public int compareTo(String s):
按字典序與參數s指定的字符序列比較大小。5.public boolean contains(String s):String
對象調用contains
方法判斷當前String對象的字符序列是否包含參數s的字符序列,例如,tom="student"
,那麼tom.contains("stu")
的值就是true,而tom.contains("ok")
的值是false。
6.public int indexOf (String str):String
對象調用方法從當前String對象的字符序列的0索引位置開始檢索首次出現str的字符序列的位置,並返回該位置。若是沒有檢索到,該方法返回的值是–1,
其相關方法:
indexOf(String s ,int startpoint)
lastIndexOf (String s)
例如
String tom = "I am a good cat"; tom.indexOf("a");//值是2 tom.indexOf("good",2);//值是7 tom.indexOf("a",7);//值是13 tom.indexOf("w",2);//值是-1
public String substring(int startpoint)
:字符串對象調用該方法得到一個新的String對象,新的String對象的字符序列是複製當前String對象的字符序列中的startpoint
位置至最後位置上的字符所獲得的字符序列。String對象調用substring(int start ,int end)
方法得到一個新的String對象,新的String對象的字符序列是複製當前String對象的字符序列中的start位置至end–1位置上的字符所獲得的字符序列。8.public String trim()
:獲得一個新的String對象,這個新的String對象的字符序列是當前String對象的字符序列去掉先後空格後的字符序列。
Java.lang
包中的Integer
類調用其類方法:public static int parseInt(String s)
int x; String s = 「876"; x = Integer.parseInt(s);
相似地,使用java.lang包中的Byte、Short、Long、Float、Double類調相應的類方法能夠將由"數字"字符組成的字符串,轉化爲相應的基本數據類型
對象的字符串表示
public String toString()
方法,一個對象經過調用該方法能夠得到該對象的字符序列表示。
String(char[]);String(char[],int offset,int length)
分別用字符數組中的所有字符和部分字符建立字符串對象public void getChars(int start,int end,char c[],int offset )
public char[] toCharArray()
8.2.StringTokenizer類
StringTokenizer類在java.util包中,有兩個經常使用的構造方法:
StringTokenizer(String s)
:爲String對象s構造一個分析器。使用默認的分隔標記,即空格符、換行符、回車符、Tab符、進紙符作分隔標記。
StringTokenizer(String s, String delim)
爲String對象s構造一個分析器。參數delim的字符序列中的字符的任意排列被做爲分隔標記。
包含方法
(1) nextToken()
:逐個獲取字符串中的語言符號(單詞),字符串分析器中的負責計數的變量的值就自動減一 。
(2) hasMoreTokens()
:只要字符串中還有語言符號,即計數變量的值大於0,該方法就返回true,不然返回false。
(3)countTokens()
:獲得分析器中計數變量的值。
8.3.Scanner類
使用Scanner類從字符串中解析程序所須要的數據。
例如,對於String對象NBA
String NBA = "I Love This Game"
;爲了解析出NBA的字符序列中的單詞,能夠以下構造一個Scanner對象。
Scanner scanner = new Scanner(NBA);
Scanner對象能夠調用方法
useDelimiter(正則表達式)
;
8.4StringBuffer類
1)StringBuffer append(String s)
:將String對象s的字符序列追加到當前StringBuffer對象的字符序列中,並返回當前StringBuffer對象的引用
StringBuffer append(int n)
:將int型數據n轉化爲String對象,再把該String對象的字符序列追加到當前StringBuffer對象的字符序列中,並返回當前StringBuffer對象的引用
2)public chat charAt(int n )
:獲得參數n指定的置上的單個字符
public void setCharAt(int n ,char ch)
:將當前StringBuffer對象實體中的字符串位置n處的字符用參數ch指定的字符替換
3)StringBuffer insert(int index, String str)
:將參數str指定的字符串插入到參數index指定的位置
4)public StringBuffer reverse()
:將該對象實體中的字符翻轉
5)StringBuffer delete(int startIndex, int endIndex)
:從當前StringBuffer對象實體中的字符串中刪除一個子字符串
6)StringBuffer replace(int startIndex,int endIndex,String str)
:將當前StringBuffer對象實體中的字符串的一個子字符串用參數str指定的字符串替換
8.5Date與Calendar類
1.Date()使用Date類的無參數構造方法建立的對象能夠獲取本地當前時間。例如Date nowTime=new Date();
2.Calendar類
使用Calendar類的static方法 getInstance()
能夠初始化一個日曆對象,
如:
Calendar calendar= Calendar.getInstance();
8.6日期的格式化
1.format方法
Formatter類的format方法:
2.不一樣區域的星期格式
若是想用特定地區的星期格式來表示日期中的星期,能夠用format的重載方法:
format (Locale locale,格式化模式,日期列表);
其中的參數locale是一個Locale類的實例,用於表示地域。
Locale類的static常量都是Locale對象,其中US是表示美國的static常量。
8.7 Math、BigInterger和Random類
1 . Math類
Math類在java.lang包中。Math類包含許多用來進行科學計算的類方法,這些方法能夠直接經過類名調用。
2.BigInterger類
java.math包中的BigInteger類提供任意精度的整數運算。可使用構造方法:
public BigInteger(String val)
構造一個十進制的BigInteger對象。
3.Random類
Random類的以下構造方法:
public Random();
public Random(long seed);
使用參數seek指定的種子建立一個Random對象
隨機數生成器random調用不帶參數的nextInt()方法:
Random random=new Random();
random.nextInt();
返回一個0至n之間(包括0,但不包括n)的隨機數
教材學習有問題先去https://shimo.im/doc/1i1gldfsojIFH8Ip/看看,若是別人沒有提出相同問題,能夠編輯文檔添加,而後把本身提出的問題複製到下面:
無
無
教材學習中的問題和解決過程, 一個問題加1分
代碼調試中的問題和解決過程, 一個問題加1分
基於評分標準,我給本博客打分:XX分。得分狀況以下:xxx
xxx
xxx
代碼行數(新增/累積) | 博客量(新增/累積) | 學習時間(新增/累積) | 重要成長 | |
---|---|---|---|---|
目標 | 5000行 | 30篇 | 400小時 | |
第一週 | 6/6 | 1/1 | 20/20 | |
第二週 | 245/251 | 1/2 | 18/38 | |
第三週 | 633/884 | 1/3 | 22/60 | |
第四周 | 305/1189 | 1/4 | 30/90 | |
第五週 | 410/1599 | 3/7 | 30/120 | |
第六週 | 1135/2734 | 3/10 | 30/150 | |
第七週 | 781/3515 | 3/13 | 30/180 |
嘗試一下記錄「計劃學習時間」和「實際學習時間」,到期末看看能不能改進本身的計劃能力。這個工做學習中很重要,也頗有用。
耗時估計的公式
:Y=X+X/N ,Y=X-X/N,訓練次數多了,X、Y就接近了。
計劃學習時間:XX小時
實際學習時間:XX小時
改進狀況:
(有空多看看現代軟件工程 課件
軟件工程師能力自我評價表)