201521123087 Java programming Eighth week of study summary

Source: Internet
Author: User
Tags comparable set time

1. Summary of this week's study

2. Written work

This job title set集合

  1. Deletion of the specified element in list (topic 4-1)
    1.1 Lab summary                                 & nbsp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          :  in the experiment, the scanner is more than just the system .In (keyboard input and the like), can also be an assigned variable, such as: Scanner in=new Scanner (nextline);

  2. Count the number of words in the text and sort by the number of occurrences (topic 5-3)
    2.1 Pseudo-code (simply write out the rough steps) For:

      traverse each word of text to establish a map map; if (str recurs) key value +1 else key =1       

    2.2 Lab summary                                 & nbsp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                          ,         &NB Sp                             A: TreeMap. It uses a custom sort of collections.sort, where collections if you want to sort the map, you can convert the map to a list,List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(tmap.entrySet());To sort.

  3. Inverted index (topic 5-4)
    3.1 Your Submission results (Advent number)
    3.2 Pseudo-code (simply write out the rough steps)
    3.3 Experimental Summary

  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 list, with several student objects used for subsequent tests.
    4.1 Using traditional methods to write a method, the Id>10,name for Zhang, age>20, gender for women, participated in the ACM Contest students screened out, put into a new collection.                                 Called in Main, and then outputs the result. For:

      • Here's how:

    The results are as follows:


    4.2 Use the stream () in Java8, filter (), collect () to write functions with 4.1 functions, and test. For:

      • At first not very will use, on the Internet query the next get a similar function code is:
        List<String> result1 = lines.stream() // convert list to stream
        .filter(line -> !"mkyong".equals(line)) // filter the line which equals to "mkyong"
        .collect(Collectors.toList()); // collect the output and convert streams to a list

    Based on the comment, you know what the code means, and then follow this rewrite and test the results as shown in 4.1, with the following code:


    4.3 When building the test set, in addition to the normal student object, add some null to the collection, and then rewrite 4.2 so that it does not appear an exception. For:

      • Since we know that listlist can be stored in null, when we add null, how do not let null affect the result, in fact, in the judgment of the conditions there to add the !=null line, the specific code is as follows.

    ⑤ generic class: Generalstack (Topic 5-5)
  5. Generic class: Generalstack (Topic 5-5)
    5.1 Your Submission results (Advent number)
    5.2 Code for Generalstack interface
    5.3 What are the benefits of generics?

  6. Generic methods
    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 is written so String max = max(strList) that it can run successfully, where strlist is the List<String> type. can also make Integer maxInt = max(intList); the operation successful, where Intlist is the List<Integer> type.
    For:

    private static <T> T max(List<T> list) { Collections.sort(list,new Comparator<T>() { @Override public int compare(T o1, T o2) { return o1.toString().compareTo(o2.toString()); } } ); return list.get(list.size()-1); }
      • With Collections.max:
        public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) { return Collections.max(coll); }

    Operation Result:

        • In the beginning, simple generics are used, because only string and integer types convert elements directly into the string class and then compare them, but if the other type is running, an error occurs.
        • It is convenient to use the method of collections to find Max.
3. Code submission record on code Cloud and PTA Experiment Summary

Topic Set:jmu-Java-05-集合

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 Experiment

201521123087 Java programming Eighth week of study summary

Related Article

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.