1. Study summary of the week 1.1 summarize set and generic related content in the way you like (mind map or other)
- Generic Partial mind Mapping
-
Summary of the collection part learning
-
java.util.Collectionis a collection interface; java.util.Collections is a wrapper class, is a tool class to implement collection
2. Deletion of the specified element in the written assignment 2.1List (title of the topic) 2.1.1 Experimental summary. and answer: List at least 2 ways to delete elements in the list
-
Experiment Summary: The output list function part--through split () to realize the segmentation; the foreach implementation iterates through the output; Deletes the list specified element function part-by traversing each element with the specified element equals ();
-
To delete an element in the list:
-
1.for Loop Traversal list Delete specified element
-
2. Enhanced for Loop
-
3.iterator traversal
-
Three methods can be used when deleting a specific element, and an iterator should be used when deleting multiple elements iterator
2.2 Count the number of words in the text and sort by the number of occurrences (title of the topic) 2.2.1 Pseudo-code (not copied code, otherwise deducted)
创建HashMap<String,Integer>读入单词遇到"!!!!!"跳出读入循环foreach遍历(遇到h中没有的key,value=1;遇到h中有的key,在原有的value基础上+1)Collections.sort实现value降序比较(value相同时,key升序排序)输出h.size()foreach输出前十的getkey()和getvalue()
2.2.2 Experiment Summary
- Using the HashMap in the Map collection, the first is to implement the reading of the word, when encountering single/multiple spaces, the use of regular expression
String[] s = x.split(" \\s+"); read-in Process method and 7-2 slightly different, encountered in the map has a key value, on the original value of the base plus 1; Conversely, the corresponding value value is 1 , implement the corresponding loop traversal, through the Map.Entry method, rewrite the Collections.sort (), the implementation of the number of descending output, encountered the same number of times, the key value ascending output; the last output hashmap.size () and the corresponding key value and number of the first ten
hashmap--when a key-value pair is required, and the order is not concerned with
treemap--when a key-value pair is required and is concerned with the natural ordering of elements
2.3 Inverted index (title) 2.3.1 Your code run results
2.3.2 Pseudo-code (no copy code, otherwise deducted)
创建`Map<String, ArrayList<Integer>> h = new TreeMap<String, ArrayList<Integer>>();`创建`ArrayList`;实现循环输入单词:如果遇到"!!!!!"跳出循环;反之,如果在h中没有找到相应的key,将其添加到h中并将所在的行数值添加到value(ArrayList)中,反之,判断当前行数是否存在于已有的value(ArrayList);创建迭代器Iterator遍历输出;(完成第一部分)输入字符串数组(正则表达式空格隔开)如果h中没有同时存在的要求单词,`System.out.println("found 0 results");`,反之,求要求单词所在行数的交集;如果不存在交集,`System.out.println("found 0 results");`,反之,输出交集及对应行数(完成第二部分)
2.3.3 Experiment Summary
- In the map creation process encountered bottlenecks, how to determine the value of the data type, through the students inspired use
ArrayList<Integer> to achieve; pre-read the word and the collection class topic similar, the first part uses the iterator iterator realizes the traverse output more direct , the most difficult part is to achieve the intersection of the number of rows and the output of the content, through a for loop nested judgment statement according to the idea of pseudo-code, step by step implementation, the topic can be said to be the most complex of a generic and set-class PTA problem
2.4Stream and Lambda
Write a student class that has the following properties:
private Long id; private String name; private int age; private Gender gender;//枚举类型 private boolean joinsACM;//是否参加过ACM比赛
Creates a collection object, such as a list
2.4.1 using traditional methods to write a search methodList<Student> search(Long id, String name, int age, Gender gender, boolean joinsACM), and then call the method to id> a value, name is a value, age> a value, gender to a value, students who have participated in the ACM contest are screened out and put into a new collection. Called in Main, and then outputs the result. (: The number of the school, name)
2.4.2 uses the stream () in Java8, filter (), collect () to write the code with the same 4.1, and test (to show the test data). When building a test collection, in addition to the normal student object, add some null to the collection, and the method you write should handle the null instead of throwing an exception. (: The school number appears)
List<Student>Newstudent= Student.Stream().Filter(E -E!=NULL&&e.getId()>2016L&&e.GetName().Equalsignorecase("Lin")&&e.Getage()> -&&e.Getgender()==Gender.Male&&e.ISJOINSACM()==true).Collect(Collectors.toList());
- The results are consistent with the above
2.5 Generic class: Code for the Generalstack2.5.1generalstack interface
2.5.2 the benefits of generics compared to the Arraylistintegerstack in previous assignments
- Using
interface GeneralStack<T> a generic definition interface, you can implement the topic requirements according to the type parameter table column Integer Double Car , greatly reducing the code redundancy, making the code more flexible and easy to modify, at the same time, you can eliminate unnecessary coercion type conversion phenomenon in the code (avoid ClassCastException )
3. Code cloud and PTA3.1 codes to submit records
3.2PTA Problem Set Completion chart
3.3 Count the amount of code completed this week
| Weekly total |
code volume |
|
New Code volume |
|
Total number |
| of new files
|
|
|
| First week |
|
189 |
|
189 |
|
10 |
|
10 |
|
| Second week |
|
304 |
|
304 |
|
9 |
|
9 |
|
| Third week |
|
557 |
|
557 |
|
10 |
|
10 |
|
| Week Four |
|
621 |
|
621 |
|
8 |
|
8 |
|
| Week Five |
|
326 |
|
326 |
|
7 |
|
7 |
|
| Week Six |
|
972 |
|
972 |
|
12 |
|
12 |
|
| Seventh Week |
|
338 |
|
338 |
|
4 |
|
4 |
|
| Eighth Week |
|
379 |
|
379 |
|
6 |
|
6 |
|
| Nineth Week |
|
492 |
|
492 |
|
5 |
|
5 |
|
4. Assess how much you understand Java
| Degree of dimension |
|
|
|
| Grammar |
|
Master the current basic Java syntax, PTA problems can be completed, but the comprehensive category of PTA problems have a certain degree of difficulty |
|
| Object-oriented design capabilities |
|
GUI interface design still needs to be improved |
|
| Application capabilities |
|
Knowledge is not deep enough, you can use the book to gradually realize the creation of small tools design |
|
| Number of lines of code so far |
|
Nearly 4000 lines |
|
201621123040 Java programming Nineth Week of study summary