小编Mic*_*yle的帖子

Java Mapping ArrayList到HashMap

我给页面获取了一个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)

我知道这是错误的做法,显然不会奏效.我对任何建议持开放态度.

谢谢

java sorting arraylist hashmap

2
推荐指数
1
解决办法
1742
查看次数

按字母顺序和按类型排序列表

我有一个仪器列表,我需要按照以下要求对它们进行排序.

订购方式:

  1. 现金
  2. 证券按字母顺序排列
  3. 管理基金按字母顺序排列

我有一个具有属性名称和类型的工具列表,我设法按名称按字母顺序排序.

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)

但我一直无法想出一种达到要求的优雅方式.

感谢任何帮助.

谢谢.

.net c# vb.net sorting list

1
推荐指数
1
解决办法
988
查看次数

标签 统计

sorting ×2

.net ×1

arraylist ×1

c# ×1

hashmap ×1

java ×1

list ×1

vb.net ×1