Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity class String[] vs List<String>

Tags:

java

hibernate

I have concern about what type of attribute best for use in Entity class. In my problem I have string attribute to persist.

I want to know what is best option to use from following ways and their pros and cons.

String[] attribute;

List<String> attribute;

Thank you

like image 268
Chandana Avatar asked Feb 13 '26 15:02

Chandana


1 Answers

If you have one string to presist, use a basic String field. If you have a fixed number of strings use String[]. If you don't know how many strings you may have, use List<String>. But, I think the List<String> is usually preferable over String[]

like image 65
zeller Avatar answered Feb 15 '26 04:02

zeller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!