201421123042 Java Programming 9th Week of study summary

Source: Internet
Author: User

1. This week study summary 1.1 summarizes the set and generic related content in the way you like (mind map or other).

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.

Experiment Summary: This question is about the deletion of the list, when traversing from the front to consider the element after the deletion of the subscript will move forward one position.
To delete an element in the list:
Delete a number greater than or equal to 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);

Operation Result:

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

Operation Result:

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>对象map来存放单词及其出现次数WHILE 取得的单词不为"!!!!!"    IF 当前单词不存在map中        将单词添加到map中,设置value值为1    ELSE        将map中该单词的value值加1新建List对象list,其中存放map实现Comparator接口对其中数据进行排序输出排序后数据
2.2 Experimental Summary

This topic to achieve the order of the title of the ArrayList implementation of the comparator interface to achieve sorting, but also use the Map.entry internal interface to traverse the element.

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)
创建Map(String,ArrayList<Integer>)对象map存放单词及其出现行数创建ArrayList对象line存放每一行句子WHILE 取得的单词不为"!!!!!"    IF 当前单词不存在map中        添加单词到map中,并将当前行数添加进value    ELSE         判断这个单词是否已经在该行出现            若没有出现,则添加该行进map的value使用Iterator迭代器遍历map并输出以空格为间隔输入若干个单词判断单词是否都存在map的同一行中若存在则输出行数及对应句子
3.3 Experimental Summary

Experiment Summary: First will create the ArrayList object line to store each row of sentences obtained by the word is not "!!!!!", add the word to map and then add the current number of rows into value. Then determine if the word has already appeared in the line, and if it does not show the value of the travel map, use the iterator iterator to traverse the map and output.
This problem is very difficult to understand is not how to find students to pay me, although the problem is made out but have not understood clearly.

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;//Enumeration type Private Boolean JOINSACM; Have you participated in the ACM contest?
Creates a collection object, such as a 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 Writing a search method using traditional methods 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;            }

Operation Result:

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)
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());

Operation Result:

5. Generic type: Generalstack

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

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

Using generics allows us to not only implement stacks that hold an integer type, but also to hold a stack of double, string, without rewriting the write interface.

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?
Still need to work hard

Week Time Total code Amount New Code Volume total number of files number of new files
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. Assess how much you understand Java

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

Dimension of degree
Grammar The problem of PTA has to learn more,
Object-oriented design capabilities Are asked students Baidu study in the effort
Application capabilities You can use Java to write some useful handyman
Number of lines of code so far 2227

201421123042 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.