Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
Core Java and Java 8
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lokesh Singh
Core Java and Java 8
Commits
c18fca52
Unverified
Commit
c18fca52
authored
Oct 03, 2022
by
Lokesh Singh
Committed by
GitHub
Oct 03, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create ArrayCheatSheets.md
parent
32e11661
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
ArrayCheatSheets.md
Working with Java Arrays and Collections/ArrayCheatSheets.md
+27
-0
No files found.
Working with Java Arrays and Collections/ArrayCheatSheets.md
0 → 100644
View file @
c18fca52
## Comparison Overview
You should be understand the differences between equals, compare and mismatch
| Method | Arrays the Same? | Arrays are Different? |
|---------------|----------------------|---------------------------------------|
|equals | true - memory address| false |
|Arrays.equals | true | false |
|Arrays.compare | 0 | negative - smaller, positive - bigger |
|Arrays.mismatch| -1 | index where arrays begin to differ |
## Arrays Compare Rules
Comparison is done by Comparators and this table will help with the rules around using compare()
| Array 1 | Array 2 | Result | Why? |
|---------------------|-----------------------|--------------|---------------------------------------------------|
|int
[]
{1,2,3} | int
[]
{1,2,3} | 0 | arrays are an exact match |
|int
[]
{1,2,3} | int
[]
{1,2} | > 0, positive| array 1 has more elements |
|int
[]
{1,2} | int
[]
{1,2,3} | < 0, negative| array 1 has less elements |
|String
[]
{"abcdefg"} | String
[]
{"abcdefg"} | 0 | arrays are an exact match |
|String
[]
{"abc"} | String
[]
{"abcdefg"} | < 0, negative| array1 is a substring of array 2 |
|String
[]
{"abcdefg"} | String
[]
{"abc"} | > 0, positive| array2 is a substring of array 1 |
|String
[]
{"abcdefg"} | String
[]
{"ABCDEFG"} | > 0, positive| Upper case is treated as smaller than lower case |
|String
[]
{"ABCDEFG"} | String
[]
{"abcdefg"} | < 0, negative| Upper case is treated as smaller than lower case |
|String
[]
{"abcdefg"} | String
[]
{null} | > 0, positive| null is smaller than any character value |
|String
[]
{null} | String
[]
{"abcdefg"} | < 0, negative| null is smaller than any character value |
|int
[]
{1,2,3} | String
[]
{"abcdefg"} | compile error| arrays must be the same data type to compare |
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment