201421123042 《Java程式設計》第9周學習總結

來源:互聯網
上載者:User

標籤:記錄   代碼   學習總結   class   lis   lin   string   system   turn   

1. 本周學習總結1.1 以你喜歡的方式(思維導圖或其他)歸納總結集合與泛型相關內容。

2. 書面作業

本次作業題集集合

1. List中指定元素的刪除(題集題目)1.1 實驗總結。並回答:列舉至少2種在List中刪除元素的方法。

實驗總結:這題考到了關於List的刪除,當從前面往後遍曆的時候要考慮到刪除了元素時後面的元素的下標都會前移一個位置。
在List中刪除元素的方法:
刪除大於等於5的數字:

        //測試資料        List<Integer> list = new ArrayList<Integer>();        for(int i=0;i<10;i++) {            list.add(i);        }
        //方法一        for(int i=0;i<list.size();i++) {            if(list.get(i)>=5) {                list.remove(list.get(i));                i--;            }        }        System.out.println(list);

運行結果:

        //方法二        for(int i=list.size()-1;i>=0;i--)            if(list.get(i)>=5)                list.remove(list.get(i));        System.out.println(list);

運行結果:

2. 統計文字中的單詞數量並按出現次數排序(題集題目)2.1 虛擬碼(不得複製代碼,否則扣分)
建立Map<String,Integer>對象map來存放單詞及其出現次數WHILE 取得的單詞不為"!!!!!"    IF 當前單詞不存在map中        將單詞添加到map中,設定value值為1    ELSE        將map中該單詞的value值加1建立List對象list,其中存放map實現Comparator介面對其中資料進行排序輸出排序後資料
2.2 實驗總結

這題要實現題目規定的排序要使用ArrayList實現Comparator介面來實現排序,還要用到Map.Entry這個內部介面來遍曆元素。

3. 倒排索引(題集題目)

本題較難,做不出來不要緊。但一定要有自己的思考過程,要有提交結果。

3.1 你的代碼運行結果

3.2 虛擬碼(不得複製代碼,否則扣分)
建立Map(String,ArrayList<Integer>)對象map存放單詞及其出現行數建立ArrayList對象line存放每一行句子WHILE 取得的單詞不為"!!!!!"    IF 當前單詞不存在map中        添加單詞到map中,並將當前行數添加進value    ELSE         判斷這個單詞是否已經在該行出現            若沒有出現,則添加該行進map的value使用Iterator迭代器遍曆map並輸出以空格為間隔輸入若干個單詞判斷單詞是否都存在map的同一行中若存在則輸出行數及對應句子
3.3 實驗總結

實驗總結:首先將建立ArrayList對象line存放每一行句子取得的單詞不為"!!!!!", 添加單詞到map中然後當前行數添加進value。再判斷這個單詞是不是已經在該行裡出現,如果沒有出現該行進map的value,使用Iterator迭代器遍曆map然後輸出 。
這個題挺難的都不怎麽懂都是找同學交我的,雖然題是做出來的但是還沒理解清楚。

4.Stream與Lambda

編寫一個Student類,屬性為:
private Long id; private String name; private int age; private Gender gender;//枚舉類型 private boolean joinsACM; //是否參加過ACM比賽
建立一集合對象,如List

        List<Student> student = new ArrayList<Student>();        student.add(new Student(1L,"wang",15,Gender.man,false));        student.add( new Student(8L,"zhao",16,Gender.woman,true));        student.add( new Student(87L,"liao",17,Gender.man,false));        student.add ( new Student(100L,"xu",18,Gender.woman,false));        student.add( new Student(67L,"liao",19,Gender.man,true));        student.add( new Student(90L,"liao",20,Gender.man,true));        student.add( new Student(177L,"liao",21,Gender.man,true));
4.1 使用傳統方法編寫一個搜尋方法List
//search方法定義    static List<Student> search(List<Student> list,Long id, String name, int age, Gender gender, boolean joinsACM){        List<Student> student = new ArrayList<Student>();        for(Student e:list){            if(e.getId()>id&&e.getName().equals(name)&&e.getGender()==gender&&e.isJoinsACM()==joinsACM){                student.add(e);            }        }        return student;            }

運行結果:

4.2 使用java8中的stream(), filter(), collect()編寫功能同4.1的代碼,並測試(要出現測試資料)。構建測試集合的時候,除了正常的Student對象,再往集合中添加一些null,你編寫的方法應該能處理這些null而不是拋出異常。(:出現學號)
List<Student> newStudent = student.stream().filter(e -> e!=null&&e.getId()>50&&e.getName().equals("liao")&&e.getAge()>18&&e.getGender()==Gender.man&&e.isJoinsACM()==true).collect(Collectors.toList());

運行結果:

5. 泛型類:GeneralStack

題集jmu-Java-05-集合之GeneralStack

5.1 GeneralStack介面的代碼
interface GeneralStack<T>{    T push(T item);                T pop();                     T peek();                   public boolean empty();    public int size();     }
5.2 結合本題與以前作業中的ArrayListIntegerStack相比,說明泛型有什麼好處

使用泛型可以使我們不止實現能夠存放Integer類型的棧,還能實現存放Double、String的棧,而不用再去重寫寫介面。

3.碼雲及PTA

題目集:jmu-Java-05-集合

3.1. 碼雲代碼提交記錄

在碼雲的項目中,依次選擇“統計-Commits曆史-設定時間段”, 然後搜尋並

3.2 PTA題集完成情況圖

需要有兩張圖(1. 排名圖。2.PTA提交列表圖)

3.3 統計本周完成的代碼量

需要將每周的代碼統計情況融合到一張表中。
自己的目標能實現嗎?
還需努力

周次 總代碼量 新增代碼量 總檔案數 新增檔案數
1 0 0 0 0
2 0 0 0 0
3 125 125 2 2
4 141 141 3 3
5 674 647 13 13
6 647 647 13 13
7 695 48 14 1
8 1867 1867 25 25
9 1974 107 29 4
10 2227 253 34 5
4. 評估自己對Java的理解程度

嘗試從以下幾個維度評估自己對Java的理解程度

維度 程度
文法 PTA的題目還得多學習,
物件導向設計能力 都是問同學百度學習在努力中
應用能力 可以使用Java編寫一些實用的小工
至今為止程式碼數 2227

201421123042 《Java程式設計》第9周學習總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.