20165310java_blog_week6
生活随笔
收集整理的這篇文章主要介紹了
20165310java_blog_week6
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2165310 《Java程序設計》第6周學習總結
教材學習內容總結
String
- 構造
- String str=new String()
- String (char a[])
- String (char a[],int startIndex,int count)
- 并置
- 常量的并置是常量(可以用==進行比較)
- 變量的并置是新對象(不能用==只能用equals()進行比較
- 常用方法
- public int length():獲得String對象的字符序列長度。
- public boolean equals(String s) :比較字符序列是否相同。
- 比較
- public boolean startsWith(String s):比較字符序列前綴是否為指定字符序列。
- public boolean endsWith(String s):比較字符序列后綴是否為指定字符序列。
- public int compareTo(String s):按字典序列與指定字符序列s比較大小。
- 索引
- public boolean contains(String s):判斷是否包含指定 字符序列
- public int indexOf(String s):返回s首次出現的位置
- public int lastIndexOf(String s):返回s最后出現的位置
- public int indexOf(String s,int startpoint):返回指定索引開始位置之后的,s首次出現的位置
- 從String獲得String新對象
- public String substring(int startpoint):返回復制指定位置到最后位置的字符序列所得到的新序列
- public String substring(int start,int end):返回復制指定開始位置到指定結束位置的字符序列所得到的新序列
- 基本數據類型轉化為String類:public static String valueOf(<基本數據類型> n)
- String類型轉化為基本數據類型:<基本數據類型> n=<相應類>.parse<相應數據類型>(s)
- 字符串轉化為字符數組
- public void getChars(int start,int end,char c[],int offset):從數組C的offset處存放String類字符序列sart到end-1處的字符。
- public char[] toCharArray():返回一個長度相等的數組。
- public String repalceAll(String regex,String replacement):用replacement字符序列替換regex匹配的序列。
public String[] split(Sring regex):存放按照regex分割的單詞在String數組中。(注意前綴是否匹配影響數組存放)
StringBuff
- StringBuff()
- StringBuff(int size)
- StringBuff(String s)
- length():獲取字符序列長度
- capacity():獲得實體容量
- append方法
- StringBuff append(String s):追加s到StringBuff中。
- StringBuff append(int n):n轉化為String類,追加到StringBuff中。
- StringBuff append(Object o):追加o的字符序列表示到StringBuff中。
StringBuff replace(int startIndex,int endIndex,String str):用str替換startIndex到endIndex-1處的字符序列。
分解字符序列
- 構造方法:
- StringTokenizer(String s):默認分隔標記分析s。
- StringTokenizer(String s,String delim):指定分隔標記delim分析s。
- 構造方法:Scanner scanner=new Scanner(str)
- 常用方法
- useDelimiter(正則表達式):利用正則表達式解析str。
- hasnext():判斷最后一個單詞是否被返回。
- next():依次返回單詞。
nextInt()或者nextDouble:依次返回單詞并進行類型轉換為int或者double型。
正則表達式:
在假期實驗樓學習和書本p186到188中都有,已經整理過不多加贅述。
Random
- public Random()
- public Random(seed)
- nextInt(int n):返回0-n之間的某個整數。
- nextDouble():返回0-1.0之間的隨機數。
- nextDouble():返回0-1.0之間的隨機數。
nextBoolean():隨機返回true或者false。
Console
- 引入java.io包
- Console cons=System.comsole()
char[] passwd=cons.readPasswoerd()
泛型
聲明對象:同樣多加一個
鏈表
- public boolean add(E element):鏈表末尾添加數據為element的新結點。
- public boolean add(int index,E element):鏈表指定位置添加數據為element的新結點。
- public boolean clear():刪除鏈表所有結點,使成為空鏈表。
- public boolean remove(E element):刪除鏈表首次出現element的結點。
- public E remove(int index):刪除指定位置結點。
- public int indexOf(E element):返回首次出現element的位置,沒有返回-1。
- public int lastIndexOf(E element):返回最后出現element的位置,沒有返回-1。
- public E set(int index,E element):替換index位置結點數據為element。
- public int size():返回鏈表長度,即結點個數。
- public boolean contains(Object element):判斷是否有結點數據為element。
- public boolean addFirst(E element):鏈表頭添加數據為element的新結點。
- public boolean addLast(E element):鏈表末尾添加數據為element的新結點。
- public E getFirst:得到第一個結點中的數據。
- public E getLast:得到最后結點中的數據。
- public E removeFirst(int index):刪除第一個結點,并返回這個結點數據。
- public E removeLast(int index):刪除最后一個結點,并返回這個結點數據。
- public Object clone():得到一個克隆列表。
- 構造: Iterator <String> iter=list.iterator()
- iter.hasNext()
- iter.next()
- public static sort(List<E>list):元素升序排列
- int binarySearch(List<T>list,T key,CompareTo<T> c):折半查找是否含有參數key
- public static void shuffle<List<E> list):洗牌
- static void rotate(List<E> list,int distance):旋轉
`public static void reserve<List<E> list):翻轉
堆棧
返回數據索引:public int search(Object data)
散列映射
- public void clear():清空
- public Object clone():返回當前散列映射的一個克隆
- public boolean containsKey(Object key):判斷是否有鍵/值對使用了參數指定的鍵
- public boolean containsValue(Object value):判斷是否有鍵/值對使用了參數指定的值
- public V get(Object key):返回用key做鍵的鍵/值對中的值
- public boolean isEmpty():判斷是否不含任何鍵/值對
- public V remove(Object key):刪除key做鍵的鍵/值對,返回對應的值
public int size():返回散列映射大小,即鍵/值對數目
樹集
- public boolean add(E o):添加結點,數據為參數o
- public void clear():刪除所有結點
- public void contains(Object o):判斷是否包含指定參數的對象
- public E first():返回第一個結點中的數據
- public E last():返回最后一個結點中的數據
- public boolean isEmpty():判斷是否空集
- public boolean remove(Object key):刪除存儲指定參數的最小結點
- public int size()`:返回結點數目
TreeMap<K,V,>
教材學習中的問題和解決過程
解決過程:和結對學習的小組成員共同討論,查找,發現問題后改正。
代碼托管
上周考試錯題總結
測試完成后補充
轉載于:https://www.cnblogs.com/atbaoi/p/8747572.html
總結
以上是生活随笔為你收集整理的20165310java_blog_week6的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Pycharm软件注册方法
- 下一篇: ACM数论之旅2---快速幂,快速求a^