Wednesday, January 2, 2019

Difference between @NotNull, @NotEmpty and @NotBlank.

@NotNull
CharSequence, Collection, Map or Array object cannot be null, however can be empty.
@NotEmpty
The CharSequence, Collection, Map or Array object cannot be null and not empty (size > 0).
@NotBlank
The string is not null and the length is greater than zero.
Here are the examples:

String test = null;
@NotNull: false
@NotEmpty: false
@NotBlank: false

String test = "";
@NotNull: true
@NotEmpty: false
@NotBlank: false

String test = " ";
@NotNull: true
@NotEmpty: true
@NotBlank: false

String name = "Some text";
@NotNull: true
@NotEmpty: true
@NotBlank: true

1 comment:

  1. Thanks you very much for sharing these links. Will definitely check this out..
    代 寫 cs

    ReplyDelete

Spring Annotations