我给页面获取了一个ArrayList <Document>,其中每个文档都有一个名为type的属性.
我不知道唯一类型或文档的数量.
我想将这个ArrayList排序为HashMap <type,document []>但是我在解决它时遇到了一些麻烦.
有些伪代码会喜欢
for (int i = 0; i < documents.size(); i++)
{
if there is an array for documents[i].type
add to this array
else create a new array for this type
add document[i].type and the array of documents with matching type to the hashmap
}
Run Code Online (Sandbox Code Playgroud)
我知道这是错误的做法,显然不会奏效.我对任何建议持开放态度.
谢谢
我有一个仪器列表,我需要按照以下要求对它们进行排序.
订购方式:
我有一个具有属性名称和类型的工具列表,我设法按名称按字母顺序排序.
Instruments.Sort(Function(x, y) String.Compare(x.Name, y.Name))
Instruments.Sort((x, y) => string.Compare(x.Name, y.Name));
Run Code Online (Sandbox Code Playgroud)
但我一直无法想出一种达到要求的优雅方式.
感谢任何帮助.
谢谢.