日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

20165310java_blog_week6

發布時間:2024/9/5 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 String toString():返回創建對象類名@對象的引用的字符串,可重寫。
  • 字符串與字節數組、字節數組
    • 字符串轉化為字符數組
    • public void getChars(int start,int end,char c[],int offset):從數組C的offset處存放String類字符序列sart到end-1處的字符。
    • public char[] toCharArray():返回一個長度相等的數組。
    • 字符數組轉化為字符串:見String類構造
    • 字符串轉化為字節數組
    • public byte[] getBytes():使用默認字符編碼,存放String的字符序列到字節數組中,并返回引用。
    • public byte[] getBytes(String charsetName):使用指定字符編碼,存放String的字符序列到字節數組中,并返回引用。(可能返回UnsupportedEncodingException異常)
    • 字符串轉化為字符數組
    • String(byte[]):用指定字節數組構造一個String對象。
    • String(byte[],int offset,int length):從字節數組offset位置取length個字節構造String對象。
  • 替換(利用正則表達式
    • 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中。
    • public char charAt(int n):得到StringBuff位置n處的字符。
    • public void setChar(int n,char ch):用ch替換StringBuff位置n處的字符。
    • StringBuff insert(int index,String str):在index位置處插入str。
    • public StringBuff reverse():翻轉StringBuff字符序列。
    • StringBuff replace(int startIndex,int endIndex,String str):用str替換startIndex到endIndex-1處的字符序列。

      分解字符序列

  • StringTokenizer(不可用正則表達式
    • 構造方法:
    • StringTokenizer(String s):默認分隔標記分析s。
    • StringTokenizer(String s,String delim):指定分隔標記delim分析s。
    • 常用方法:
    • hasMoreTokens():查看計數變量是否大于一。
    • nextTokens():逐個獲取String對象單詞。
    • countTokens():獲得計數變量的值。
  • Scanner(可用正則表達式)
    • 構造方法: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()

      泛型

  • 泛型類聲明:class 名稱<泛型列表>
  • 聲明對象:同樣多加一個

    鏈表

  • 構造:LinkedList<String>mylist=new LinkList<String>()
  • 常用函數
    • 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):翻轉

      堆棧

  • 創建:Stack<E>
  • 壓棧:public E push(E item)
  • 彈棧:public E pop()
  • 判斷是否空棧:public boolean empty()
  • 獲取棧頂數據:public E peek()
  • 返回數據索引:public int search(Object data)

    散列映射

  • 構造:HashMap<String,Student> hashtable=HashSet<String,Student>()
  • 常用方法
    • 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():返回散列映射大小,即鍵/值對數目

      樹集

  • 構造:TreeSet<E>
  • 常用方法:
    • 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,>

      教材學習中的問題和解決過程

  • Mac中一個字符占三個字節,一開始以為占兩個字節,導致運行結果是亂碼
  • 解決過程:和結對學習的小組成員共同討論,查找,發現問題后改正。

    代碼托管



    上周考試錯題總結

  • 測試完成后補充

轉載于:https://www.cnblogs.com/atbaoi/p/8747572.html

總結

以上是生活随笔為你收集整理的20165310java_blog_week6的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。