1. This week study summary 1.1 summarizes the set and generic related content in the way you like (mind map or other).
Mind Map 1: (Some changes and refinements are made to the collection section.)
Mind Map 2: (generic type)
1.2 Choose: Collect code snippets that you think are useful
Code Snippet 1:(taken from PPT)
To delete an element using an iterator:
List<String> list = new ArrayList<>(); list.add("a"); list.add("b"); list.add("c"); Iterator<String> iterator = list.iterator(); System.out.println(list); while (iterator.hasNext()) { iterator.next(); iterator.remove(); } System.out.println(list);
Run:
Code Snippet 2:(taken from PPT)
Set (set)-hashset:
Set<String> strSet = new HashSet<>(); strSet.add("1"); strSet.add("z"); strSet.add("2"); strSet.add("a"); strSet.add("1"); for (String e : strSet) { System.out.println(e); }
Run:
It was strange why the output order of the running result elements did not follow the order in the code, and then asked a big guy, saying it was becauseHashSet里面是无序的,它是按元素的哈希值来决定他的顺序
2. Written work
Collection of this homework question set
Deletion of the specified element in 2.1.List (topic set) 2.1.1 Experimental summary. and answer: List at least 2 ways to delete elements in the list.
Method:
public E remove(int index)
: Removes an element from the specified position in this list. Move all subsequent elements to the left (index minus 1).
public void clear()
: Removes all elements from this list.
Summary: the whole is still relatively simple, when doing the main problem is in the input string processing, at first I want to convert the input string into a character array, but if using the ToCharArray () method after conversion, I do not know how to implement the topic 以空格(单个或多个)为分隔符,将line中的元素抽取出来,放入一个List
this request, later is to see a group of students with split method, so Baidu a bit this method:
Split is the meaning of segmentation, which is mainly to divide the string into an array according to the specified symbol.
Then it solves the problem by using this method directly.
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)
Steps:
1. According to the previous question, has done the statistics of the number of words, although the subject does not use alphabetical order, but still for the convenience of using the previous question TreeSet
2. To change the need to count the number of occurrences of each word, consider using HashMap to achieve a count of each word
3. Override the Sort method in collections to compare and sort each word count in the collection
4. Output
2.2.2 Experiment Summary
Summarize:
This problem feels more difficult to do, especially in the second step of the implementation. Although want to use HASHMAP data type but do not know what method, and then refer to the code of the classmate, found that you can use the ContainsKey method to count the number of words.
2.3 Inverted index (title)
The subject is more difficult, do not come out does not matter. But must have own thinking process, must have the submission result.
2.3.1 your code to run the results
Run result 1:
2.3.2 Pseudo-code (no copy code, otherwise deducted)
Steps:
The processing of the input and the number of lines of text:
1. Read the text in a row, using a dynamic array to hold the text entered for each line
2. In each line of text input, define a string array, use the Split function to do a string separation, and define a variable to mark the number of rows.
Establishment of MAP mapping table: (Key: String value: Corresponding number of rows)
3. Iterating through an array
4. Establish the map map for the first occurrence of the word and modify the map map for the first occurrence of the word
5. Print the Index Table
Query word output corresponding word line number:
6. Input string literals are still delimited
7. Handle the case when entering one, two, or more words. ----> defines two dynamic arrays, one for the row count of the first word, and the second for the intersection of the different words that are traversed and the number of lines of the first word.
8. Output
2.3.3 Experiment Summary
Summarize:
This problem for me is more difficult, the topic looked for a long time, there is no idea. The first thing to do is to deal with the input and labeling of the number of rows, and later a roommate said that you can use two arrays to solve, the outside of the dynamic array to enter a row of strings, and then use an array to do dynamic array delimited array of words. So that's how I used it. Another problem is that when dealing with the intersection of words, it is thought that the first array is fixed to keep one word line number unchanged, the second array to constantly change, summing the intersection of the first array. So I thought the first array does not need to use dynamic, but I ignored the first array is to hold the word corresponding to the number of lines, not sure the number of input words corresponding to a few, data or dynamic changes, in fact, two are to use dynamic array.
As for the subsequent running results ... Also tried a lot of possibilities.
For example 1:
Input a text inside no, the program does not respond, later found missing a consideration point:
For example 2:
This I found with the output of the answer is not the same, but PTA actually let me cross ... Then I checked, because in the first for inside I added {}, and then led to the back of the loop a bit messy, more print out something .... (For this problem is really no solution, because this error was found two or three hours:: >-<::)
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;//Enumeration type Private Boolean JOINSACM; Have you participated in the ACM contest?
Creates a collection object, such as a list
2.4.1 using traditional methods to write a search method list
Part of the code:
Run:
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)
Key code:
List<Student> students=stuList.stream().filter(stu1->stu1!=null&&stu1.getId()>10L&&stu1.getName().equals("zhang")&&stu1.getAge()>20&&stu1.getGender().equals(Gender.girl)&&stu1.isJoinsACM()).collect(Collectors.toList());
Run:
2.5 generic type: Generalstack
The Generalstack of jmu-java-05-collection of title set
2.5.1 Code for Generalstack interface
Interface code:
interface GeneralStack { public Object push(Object item); public Object pop(); public Object peek(); public boolean empty(); public int size(); }
2.5.2 the benefits of generics compared to the Arraylistintegerstack in previous assignments
Benefits: Arraylistintegerstack directly qualifies the data type as an integer type, while using a generic method that defines the Generalstack interface, the operation of the interface applies to any reference type of data, which I think is more flexible, You can also avoid the risk of casting.
3. Code Cloud and PTA
Topic Set: jmu-java-05-Collection
3.1. Code Cloud codes Submission record
In the Code cloud Project, select statistics-commits history-set time period, and then search for and
3.2 PTA Problem set complete situation diagram
Two graphs are required (1. Ranking chart. 2.PTA Submission list diagram)
Ranking chart:
PTA Submission List diagram:
3.3 Count the amount of code completed this week
The weekly code statistics need to be fused into a single table.
Week number |
Number of rows |
number of new rows |
Number of files |
number of new files |
1 |
57 |
57 |
5027 |
5027 |
2 |
400 |
400 |
10 |
10 |
3 |
508 |
508 |
23 |
13 |
5 |
609 |
609 |
31 |
8 |
6 |
612 |
612 |
40 |
9 |
7 |
584 |
584 |
46 |
6 |
8 |
432 |
432 |
50 |
4 |
9 |
620 |
620 |
56 |
6 |
10 |
468 |
468 |
60 |
4 |
Can you achieve your goals?
Basic can ....
4. Assess how much you understand Java
Try to evaluate how much you understand Java from the following dimensions
Dimension of |
degree |
Grammar |
PTA Most of the topic can be done, some of the more difficult grammar has not mastered, the basic grammar some will forget |
Object-oriented design capabilities |
You can basically use object-oriented thinking to model the problem you want to solve, but sometimes it takes a long time to |
Application capabilities |
You can use Java to write some x applets |
Number of lines of code so far |
4290 |
201621123062 Summary of the Nineth Zhou of Java programming