How to make duplicate check logic more readable

Have the data you want to check for duplication in List type. If it is a DB record, it will be fetched by SQL. On top of that, for example, when checking for duplicate character strings,

sample.java


String searchStr = 'The string you want to look up';
List<String> dataList =  'Data to be examined';

if(dataList.contains(searchStr)){
   //Processing when duplicated

} else {
   //Processing when there is no duplication

}

If you write it like this, it will be easier to understand when you look at it later.

Recommended Posts

How to make duplicate check logic more readable
How to make shaded-jar
[AWS] How to check logs
How to check JSF version
[Rails] How to make seed
How to make a Java container
How to make a splash screen
How to make a Jenkins plugin
How to make a Maven project
How to make a Java array
[Android] How to make Dialog Fragment
How to check Java installed on Mac
How to prevent duplicate processing by addEventListener
How to make a Discord bot (Java)
Let's migrate to make Java more comfortable
How to make asynchronous pagenations using Kaminari
How to check the logs in the Docker container
How to make Spring Boot Docker Image smaller
How to make a lightweight JRE for distribution
How to make Unity Native Plugin (Android version)
How to make a follow function in Rails
How to check Rails commands in the terminal
How to make an crazy Android music player
[Java] How to make multiple for loops single
How to deploy
How to make an image partially transparent in Processing
How to make batch processing with Rails + Heroku configuration
How to make LINE messaging function made with Ruby
How to make an oleore generator using swagger codegen
How to make Java unit tests (JUnit & Mockito & PowerMock)
How to make an almost static page with rails
How to make JavaScript work on a specific page
How to check only one RadioButton check by default (Note)
How to make Laravel faster with Docker for Mac
How to check CircleCI code and automatically deploy to Heroku
How to make a cache without thinking too much
How to make a mod for Slay the Spire
[Linux] Easy commentary! How to check and change permissions