Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
do-happy
JavaTutorial
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
JavaTutorial
/
src
/
main
/
java
/
javaStudy
/
collectors
/
note.txt
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
18 lines (14 loc) · 1.17 KB
master
Breadcrumbs
JavaTutorial
/
src
/
main
/
java
/
javaStudy
/
collectors
/
note.txt
Copy path
Top
File metadata and controls
Code
Blame
18 lines (14 loc) · 1.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1.对于已知得场景,要指定集合的初始容量。(可以减少资源的消耗)
2.asList的缺陷(入参为泛型类型):
(1)asList的参数为泛型的变长参数,若入参类型不为泛型,则会出错
例如:int[] ins = {1,2,3,4,5};
System.out.println(Arrays.asList(ins).size()) -> 1
原因:因为ins类型为int,无法泛型化,不能作为asList的参数,
但是int类型的数组可以泛型化,可以就相当于入参为一个数组,即结果为1
(2)asList返回的列表只是披着list的外衣,但是没有list的基本特性(变长),所以在使用asList之后
不要试图去改变asList返回的列表,否则会出现问题
3.subList(用于对List进行分割)的缺陷:
subList()分割的其实是原表的一个视图,但是子列表的操作都会反应在原列表上。
4.保持compareTo和equals同步
对于compareTo和equals两个方法我们可以总结为:compareTo是判断元素在排序中的位置是否相等,
equals是判断元素是否相等,既然一个决定排序位置,一个决定相等,所以我们非常有必要确保当排序位置相同时,其equals也应该相等。
You can’t perform that action at this time.