Question on #java# : Why does the query return list

qa3601103 注册会员
2023-02-27 15:37

This method is a conditional query. The conditional query cannot guarantee that only one piece of data can be queried, so the set is used as the return type.
set is fine, and you can even use Map to see if the business needs it. But basically no one will use Set, the data found in the database, generally in the sql to redo the operation.

dhn8112 注册会员
2023-02-27 15:37

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > in the programming, the return type is usually associated with the required data structure and data types. The main reason a list is returned as a result of a query is that a list is an ordered data structure that can contain repeating elements and supports operations such as indexing and slicing, which makes a list ideal for representing a collection of multiple results.
In contrast, a set is an unordered data structure that cannot contain duplicate elements and does not support operations such as indexing and slicing. Therefore, if the query results need to be de-duplicated or do not need to be sequenced, consider using a collection as the return type.
In addition to lists and collections, other types can be used as return types for query results, such as tuples, dictionaries, and so on. The choice of the return type depends on the characteristics and usage scenarios of the query results.

duron571 注册会员
2023-02-27 15:37

This is usually based on the query results to determine what type of value is returned; As shown below:


① If you are using the first data format, you will usually use List or Map. Usually the data that is returned is a List(that is, many pieces of data) and you use a List;
② If you are the second data format, generally use an object to receive, such as only one data echo;

If you have any questions, you can send me a private message at any time.

About the Author

Question Info

Publish Time
2023-02-27 15:37
Update Time
2023-02-27 15:37

Related Question




如何从Python数据库检索后转换列表为Json ?

clion创建hello world报错


conda executetable isnot found



错误:AddressSanitizer: heap-buffer-overflow on address