Skip to content
Advertisement

For loop inside for loops code optimisation

I have an loop inside loop to remove the elements from the seconde loop, and what is present in the list has to perform certain actions. I wish to optimize the iteration and comparisons, can it be done?

How do I optimize my logic shown below to avoid so many lines of code

JavaScript

Advertisement

Answer

After minLenghtOfEntities += field.getFieldLength(); a break is missing.

With streams the code becomes a bit more structured, first collecting the fields to remove and then the entity lengths to correct.

JavaScript

Unfortunately because of contains a Set<String> ignoreFields is not better.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement