


Java determines whether an instance of an element exists in an array or collection
Introduction:
Today a friend in the group asked "How to know whether an array collection already exists the current object?" Everyone knows about circular comparison, including me, a great group member. Is there any other way? Let’s take a look at this article.
Text:
The people you can find here are all programmers. It should be clearer to directly enter the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
Running results:
1 2 3 4 5 |
|
Let’s summarize~. =
1) There are at least three types of arrays:
A) binarySearch(,). But the condition is that it needs to be sorted in advance, and the overhead needs to be considered.
B) Regex. However, the array needs to be converted into a string. The method provided by the Arrays class will introduce the three delimiters ", [ ]", which may affect the determination result.
C) Circular comparison.
2) There are at least two types of collections:
A) Loop. If it is only determined to exist by default (non-customized existence), it is recommended not to consider it directly.
B) contains. If you can get closer, do it decisively.
3) Sets provide operations similar to "addition and subtraction", so you can pay attention to them.
The above is the entire content of the java examples brought by the editor to determine whether an element exists in an array or collection. I hope you will support the PHP Chinese website~
More java determination arrays Or whether there is an instance of a certain element in the collection. For related articles, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

Start Spring using IntelliJIDEAUltimate version...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Analysis of memory leak phenomenon of Java programs on different architecture CPUs. This article will discuss a case where a Java program exhibits different memory behaviors on ARM and x86 architecture CPUs...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

How to convert names to numbers to implement sorting within groups? When sorting users in groups, it is often necessary to convert the user's name into numbers so that it can be different...
