Learn Java 16th Day Personal Summary

Source: Internet
Author: User
Tags comparable

DAY16 Personal Summary

First, TreeMap Collection

1 , Concept:

The TreeMap collection is ordered, and because it is ordered, it is possible to override the Comparato () in the comparable interface by the class, sort the collection, and remove duplicates, At the same time, TreeMap collections and TreeSet collections can be customized by using custom sorting by creating a custom sort comparer.

2 , use the following:

The K in the treemap<k,v>,<> generic represents the key value V for value, and the key value is unique and non-repeatable, and value values can be duplicated.

Implement the Comparato () method in the comparable interface:

Public class Company implements comparable<company>{

@Override

Public int compareTo (company O) {

}

}

Custom sorting

Public class Mycomparator implements comparator<student>{

@Override

Public int Compare (Student O1, Student O2) {

}

}

Sort by:

If the caller is greater than the parameter return positive represents ascending, the inverse represents descending

Second, the properties set

1 , features:

Properties collection is unordered and does not allow duplicates , the Properties collection is often used to store configuration files and to store configuration information that can help persist data, stored type key values and values must be of type string, and allow null but only one, and null values are also non-repeatable.

2 , how to use:

Properties Properties = new Properties ();

properties.setproperty ("a", "AAA");

       properties.setproperty ("C", "CCC");

       properties.setproperty ("B", "BBB");

       properties.setproperty ("B", "BBB");

       System. out . println (properties);

       String value  = Properties.getproperty ("b");

       System. out . println (value);

 

Iii. the difference between Hashtable and Hahsmap (classic interview)

The comparison is as follows:

Hashtable

HashMap

Initial capacity is 11

Initial capacity is 16

The key value is not allowed to be null

Allow to have a null

Thread is secure

Thread is not secure

rewrite hashcode method has been improved by some

Directly with the original hashcode

Iv. generic type <>

1 , Concept:

Generics to support the creation of classes that can be parameterized by type. You can think of a type parameter as a placeholder for the type that you specify when you use a parameterized type, as if the form parameter of the method is a placeholder for the value passed at run time.

2 , generic values represent the meaning

T type

E element

K Key

V value

<T> represents generic generics and can be replaced with any data type T

<t extends person> the restricted generics can only be replaced by the person and the subclass of the person T

3, Collections Class

Use the following:

1. Multiple elements can be added to the collection at the same time

Collections.addall (List2, new B (4), new B (2), new B (3));

2, using the binary method to find the set, (the premise set must be ordered)

int index = Collections.binarysearch (List2, New B (2));

4. IO stream

1 , character stream, and byte streams

Simple word stream is directly open can read text such as TXT document, is a character stream, can not read is the word stream such as mp3 files, video files mp4, etc.

2 , process flow, and node flow

The process flow is a stream that does not directly touch the file or touches other operations called a filter stream.

Node streams are called node streams when they are directly in touch with file operations.

3 , the buffered stream is called the memory stream

Buffer flow has higher execution efficiency than node flow and processing flow

5. File class

The construction method uses the following:

Common methods are as follows:

Learn Java 16th Day Personal 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.