1.1 以你喜歡的方式(思惟導圖或其餘)概括總結集合與泛型相關內容。
java
1.2 選作:收集你認爲有用的代碼片斷數組
本次做業題集集合網絡
1. List中指定元素的刪除(題集題目)
1.1 實驗總結。並回答:列舉至少2種在List中刪除元素的方法。
這道題中,當空格數量不一樣時,用String[] str==line.split(" +")分開。
可用remove()方法刪除元素學習
public static void remove(List<String> list, String word) { for (int i = list.size()-1;i>=0; i--) { if(word.equals(list.get(i))){ list.remove(i); } } } //迭代器刪除 public static void remove(List<String> list, String word) { for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) { String str = (String) iterator.next(); if (str.equals(word)) iterator.remove(); } }
2. 統計文字中的單詞數量並按出現次數排序(題集題目)測試
2.1 僞代碼(不得複製代碼,不然扣分)設計
建立HashMap對象map; 讀入字符串; 當遇到!!!!!時退出; 當map中不存在word時times=1; 當map中存在word時times+1; 建立ArrayList對象list; 用Collections.sort()排序; 輸出map長度; 輸出前十個數據;
2.2 實驗總結code
List<Map.Entry<String,Integer>> list=new ArrayList<Map.Entry<String,Integer>>(map.entrySet()); Collections.sort(list,new Comparator<Map.Entry<String,Integer>>(){ public int compare(Map.Entry<String,Integer>o1,Map.Entry<String,Integer>o2) { if(o1.getValue()==o2.getValue()){ return o1.getKey().compareTo(o2.getKey()); } if( o1.getValue()>o2.getValue()) return -1; else return 1; } });
這道題是主要把Map中的鍵值對放進ArrayList,而後用Collections.sort()排序。
3. 倒排索引(題集題目)對象
本題較難,作不出來沒關係。但必定要有本身的思考過程,要有提交結果。
3.1 截圖你的代碼運行結果
3.2 僞代碼(不得複製代碼,不然扣分)blog
建立TreeMap; 當不爲!!!!!時輸入行數,當爲!!!!!時break; 將輸入的用split分開放到數組; 當map裏面包含Word時,獲得這個Word的行數,並把這個行數加入到list; 輸入put(字符,有包含字符的行數); 而後輸出map;
3.3 實驗總結排序
這道題還沒作出來,思路是把單詞對應的行數放到list中,而後輸出,但尚未作出來,因此沒有運行截圖。
4.Stream與Lambda
編寫一個Student類,屬性爲: private Long id; private String name; private int age; private Gender gender;//枚舉類型 private boolean joinsACM; //是否參加過ACM比賽
建立一集合對象,如List
4.1 使用傳統方法編寫一個搜索方法List
public static void main(String[] args) { List<Student> stu = new ArrayList<Student>(); stu.add(new Student((long) 58,"xiao",15,Gender.man,false)); stu.add( new Student((long) 54,"an",16,Gender.woman,true)); stu.add( new Student((long) 100,"an",17,Gender.man,true)); stu.add ( new Student((long) 82,"zhang",18,Gender.woman,true)); stu.add( new Student((long) 90,"zhang",19,Gender.woman,true)); List<Student> stu1 = search((long) 80, "zhang",18,Gender.woman, true,stu) System.out.println("網絡1611張凱豔"); for (Student student : stu1) { System.out.println(student); } } public static List<Student> search(Long id, String name, int age, Gender gender, boolean joinsACM,List<Student> list){ List<Student> stu = new ArrayList<Student>(); for(Student e:list){ if(e.getId()>id&&e.getName().equals(name)&&e.getGender()==gender&&e.isJoinsACM()==joinsACM){ stu.add(e); } } return stu; }
4.2 使用java8中的stream(), filter(), collect()編寫功能同4.1的代碼,並測試(要出現測試數據)。構建測試集合的時候,除了正常的Student對象,再往集合中添加一些null,你編寫的方法應該能處理這些null而不是拋出異常。(截圖:出現學號)
List<Student> stu1 = stu.stream().filter(e -> e!=null&&e.getId()>80&&e.getName().equals("zhang")&&e.getAge()>=18&&e.getGender()==Gender.woman&&e.isJoinsACM()==true).collect(Collectors.toList());
5. 泛型類:GeneralStack
5.1 GeneralStack接口的代碼
interface GeneralStack<T>{ public T push(T item); public T pop(); public T peek(); public boolean empty(); public int size(); }
5.2 結合本題與之前做業中的ArrayListIntegerStack相比,說明泛型有什麼好處
在之前做業中的ArrayListIntegerStack
中若是已經肯定了棧中元素的類型,那麼元素類型就是肯定不能改變的,而若是用泛型時能夠選擇改變元素的類型,比較靈活。
3.1. 碼雲代碼提交記錄
3.2 截圖PTA題集完成狀況圖
3.3 統計本週完成的代碼量
周次 | 總代碼量 | 新增代碼量 | 總文件數 | 新增文件數 |
---|---|---|---|---|
2 | 381 | 381 | 12 | 5 |
3 | 661 | 280 | 19 | 7 |
4 | 974 | 313 | 24 | 5 |
5 | 1358 | 384 | 33 | 9 |
6 | 2211 | 853 | 37 | 4 |
7 | 3223 | 412 | 42 | 5 |
8 | 3635 | 423 | 46 | 4 |
4. 評估本身對Java的理解程度
嘗試從如下幾個維度評估本身對Java的理解程度
維度 | 程度 |
---|---|
語法 | PTA的題目只能作出一小部分,語法還不是很熟練 |
面向對象設計能力 | 還比較差 |
應用能力 | |
至今爲止代碼行數 | 3635 |