201621123037 Java Programming 9th Week of study summary

Source: Internet
Author: User

Job 09-Collection and generic Z1. This week's study summary 1.1 summarizes the set and generic related content in the way you like (mind map or other).

This time to change a way, you do not have a mind map, with a combination of graphics and text to summarize

1. Map three views
* Key value: Set

2. Traversing a key/value pair set
The code is described in 1.2

3. Java8 New syntax
Figure....

4. Delete the specified element
Summary See below 1.2

1.2 Choose: Collect code snippets that you think are useful
    • Traversing a key/value pair set
Map<String,String> map = new HashMap<String,String>();for(Map.Entry<String, String> entry:map.entrySet()){     String key = entry.getKey();    Employee value = entry.getValue();    
    • Delete the specified element (List)

After adding entry

for(int i = 0;i<integerList.size();i++){    if(integerList.get(i)<3)        integerList.remove(i);}

This will cause the traversal skipping element to occur, so use the following method instead:

for (int i=list.size()-1;i>=0;i--) {                if((list.get(i)).equals(str)){                list.remove(i);}}

In reverse order to remove the phenomenon of skipping elements will not occur.

2. Written work

Collection of this homework question set

1. Deletion of the specified element in list (title of topic) 1.1 Experimental summary. and answer: List at least 2 ways to delete elements in the list.

For:

In the subject

/Use a space (single or multiple) as a delimiter to extract the elements of line into a list/
public static List

This function, which focuses on taking a space-delimited element out of the list, uses the Str.next () method to get the element before the space, while Scanner can not only get the contents of the console input, but also read the string, such as:Scanner SC = new Scanner (line); Where line is the string

The next function

/ Remove the same element as the STR content in the list /
public static void Remove (List

There are two methods of deleting elements:

1. Method One

for (int i=list.size()-1;i>=0;i--) {                if((list.get(i)).equals(str)){                list.remove(i);}}

The reverse method is used to remove duplicate elements one by one, eliminating the problem of skipping elements caused by the change of subscript after deletion.
PS: Note the maximum subscript in reverse order is list.size ()-1

2. Method Two

for (int i = 0; i < list.size(); i++) {            if(list.get(i).equals(str)){                list.remove(i);                 i--;            }

Contrast method One, this is the conventional way of thinking-positive sequence traversal, but prone to skip the element problem.
Workaround:
After each judgment, the bottom value I will return ' i--' to the previous skipped element.

2. Count the number of words in the text and sort by the number of occurrences (title of the topic) 2.1 Pseudo-code (not copy code, otherwise deducted)
Map<String,Integer> wordmap = new TreeMap<>();                                                                //创建map对象while循环下    if(word.equals("!!!!!"))         break    else if(map.countiansKey(word))        map.put(word,map.get(word)+1)                                //重复+1    else         map.put(word,1)                                             //未重复为初始的1    List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(wordmap.entrySet());                                                                         //改成list对象Collections.sort(list,new Comprartor<Map.Entry<String,Integer>>() ) {                                                                    //对第二个参数进行排序    进行排序比较}for(遍历list前十个)list.get(i).toString()                                               //输出
2.2 Experimental Summary

For:
The key is how to put the word into the map object while traversing. The first thing to judge is "!!!!! "At the end, on this basis, if it exists, put value +1, otherwise add the word, value=1.
And then just convert it to a collection object to sort it, and that's where the previous comparator

3. Inverted index (problem set)

The subject is more difficult, do not come out does not matter. But must have own thinking process, must have the submission result.

3.1 Your code runs the result

3.2 pseudocode (Do not copy code, otherwise deduct)

For:

Map<String, ArrayList<Integer>> map = new TreeMap<String, ArrayList<Integer>>();while (sc.hasNextLine()) {    if (str.equals("!!!!!"))                 break;    else        if (str.length() == 0)                     continue;        str1=str.split(" +");        for 遍历数组str1            if (map.get(str1[j]) == null)                 添加到值中            else                不重复则添加值中}for 遍历输出(遍历输出函数方法见上1.2选作题)
f(wordmap.get(word) == null)        print("found 0 results")    else         print(要求输出的格式)
3.3 Experimental Summary

For:
This problem note that the first time you put a map object, you want to back up the content and add it to the list object for subsequent query output.
When the input content is read, the whole line can be read with nextline (), convenient to calculate the number of rows, followed by the entire string of Str.split ("+"); Operation, the formation of a character array is convenient to store the map object.

4.Stream 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

4.1 Writing a search method using traditional methods list


4.2 Use 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) 5. Generic type: Generalstack

The Generalstack of jmu-java-05-collection of title set

5.1 Code for Generalstack interface
public interface GeneralStack<E> {    E push(E item);             E pop();                     E peek();                   public boolean empty();    public int size();    }
5.2 What are the benefits of generics compared to arraylistintegerstack in previous assignments?

For:
In the previous job in the Arraylistintegerstack, the elements placed in the stack can only be an integer type, other types of elements are error; now generics circumvent this limitation, so that for the stack, no matter what type of data is stored internally, The basic operation is independent of the specific type of the element.

6. Select: Generic method

The base reference file is Genericmain and is modified on this file.

6.1 Write Method Max, which returns the maximum value of all elements in the list. The elements in the list must implement the comparable interface. The Max method you write should make string max = Max (strlist) run successfully, where Strlist is List6.2: The existing user class, whose subclasses are Stuuser, and both implement the comparable interface. Writing method Max1, the basic ability of the same 6.1, so that user user = Max1 (stulist), can run successfully, where Stulist is List6.3 selected: Write int mycompare (t O1, T O2, Comparator C) method, The method can compare two user objects, or compare two Stuuser objects, and the incoming comparer C can be Comparator7. Selection: Inverse maximal matching segmentation algorithm

Set the No. 07 Experiment (collection) in the experiment file. doc file, inside the topic 6.

7.1 Write pseudo-code (not directly copied code) 7.2 Your code runs the result. 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)



3.3 Count the amount of code completed this week

The weekly code statistics need to be fused into a single table.
Can you achieve your goals?

4. Assess how much you understand Java

Try to evaluate how much you understand Java from the following dimensions

Degree of dimension
Grammar PTA Topic has been able to easily take care of, there is nothing difficult to pour my grammar problems
Object-oriented design capability can skillfully use object-oriented thinking to model the problem to be solved
Application capabilities You can use Java to write some useful gadgets
Number of lines of code so far 5000

Optional: 5. Use Java to solve real-world problems

There are n courses where each student has a few questions about each course (each subject has a label). Teachers expect to classify the problems of all students, first classifying the problems by course, and classifying the same student's topic in some category. The existing operation process is that each student does not know the subject in his own subjects according to the course classification number after the issue to the Study Committee members to study the unified summary. It is now hoped that a program will be developed to help students categorize and to count which topics in each course do not understand the highest rate. Trying to write out the approximate steps to solve the problem? The contents of each student's document should follow a certain standard to facilitate the process, try to write the specification.

201621123037 Java Programming 9th Week of study summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.