Study Number: 201521123116 Java programming Seventh week of study summary

Source: Internet
Author: User

1. Summary of this week's study

2. Written work Q1 ArrayList Code Analysis 1.1 explains ArrayList contains source code
ArrayList's contains source code

1.2 ExplanationE remove(int index)Source

1.3 In conjunction with 1.1 and 1.2, what types of elements do you need to consider when storing data ArrayList?

The types of the parameters in ArrayList are all object classes, andthe object class is the parent class for all classes, so you do not need to consider the type of the element.

1.4 Analysis Add source code, answer when the internal array capacity is not enough, what to do?

Put a label on it

Ensurecapacityinternal will determine if you want to enlarge.

1.5 Analyzing the private Voidrangecheck (intindex) source code, why should the method be declared private and not declared as public?

Avoid being accessed by the outside world, when Rangecheck (int index) is called, a reminder is sent when the array crosses out, and this is an internal method that is not necessarily declared public.

HashSet Principle 2.1 Add an element to the HashSet (hash set), how is its storage location determined? which methods need to be called?
    • When an element is accessed from HashSet, HashSet evaluates the element's Hashcode value first, and then takes the element out of the hashcode corresponding position.
    • To invoke the Equals and Hashcode methods

    • 2.2 Optional: After attempting to parse the HashSet source code, re-interpret 1.1

      Using the contain method in HashSet the speed of the contain method in the list is simply

          public boolean contains(Object o) {      return map.containsKey(o); }

The list is traversed and hashset is used to quickly find and compare with equals, and when the comparison value is true, overwrite the original value if False is inserted into the hash bucket.

ArrayListIntegerStackQ3 ArrayListIntegerStack3.1 compares himself to write Arraylistintegerstack with himself in the topic set jmu-java-04-Object-oriented 2-advanced-polymorphic, interface with the internal class topic 5-3 custom Interface Arrayintegerstack, what's the difference? (Do not show a large segment of code)
    • Arraylistintegerstack is implemented using ArrayList to implement the stack, Arrayintegerstack is implemented with an integer array.
    • Arrayintegerstack capacity is limited, there will be a full situation, Arraylistintegerstack does not exist in the case of full stack.
    • Arrayintegerstack need to define a top to go into the stack, and arraylistintegerstack do not need, directly in the existing method can be implemented into the stack.
3.2 Simple description of the benefits of the interface.

The Arrayintegerstack,,arraylistintegerstack all implement the Integerstack interface.

Stack and Queue4.1 write a function to determine whether a given string is a palindrome, be sure to use the stack, but not use the Java stack Class (for specific reasons to search). Please paste your code, the class name is main your school number.

public class Main201521123116 {
public static void Main (string[] args) {
Scanner sc=new Scanner (system.in);
String A=sc.next ();
System.out.println (Ishuiwen (a));
}

public static Boolean Ishuiwen (String text) {
Arraylistintegerstack stack=new arraylistintegerstack ();
/
*
*arraylistintegerstack is the stack defined in experiment 5-1 this week
*/

char []b=text.tochararray ();
int length=b.length;
for (int i=0;i<length/2;i++)
{
if (B[i]!=b[length-i-1]) {
return false;
}
return true;
}
}

4.2 jmu-java-05-set of 5-6 Bank business queue simple simulation. (Do not show a large segment of code)

Set up two queues A and B, add the numbers placed in the array to queue A and B, respectively, according to the odd even number, and then test instructions output

Q5 the number of words in statistical text and sorts them alphabetically by Word output 5.1 experimental summary
Set<String> str = new TreeSet<String>();        Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String s = sc.next(); if (!s.equals("!!!!!")) str.add(s); else break; } System.out.println(str.size()); for (int i = 0; i < 10; i++) { System.out.println(str.toArray()[i]); }

With TreeSet, it has the automatic sorting function. The title only requires 10 words so it is best to add Str.toarray () [I];pta submit correctly.

3. Code submission record on code Cloud and PTA Experiment Summary

3.2 PTA Experiment

Programming (5-1, 5-2, 5-3 (optional), 5-6)
The experimental summary has been reflected in the homework, do not write.

Study Number: 201521123116 Java programming Seventh 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.