You can use @Size as bean validation annotation so validate the size of a collection, map, array or charSequence.
see the documentation at https://jakarta.ee/specifications/bean-validation/3.0/apidocs/jakarta/validation/constraints/size