什么时候应该使用字典、列表或集合?

是否存在更适合每种数据类型的场景?

我正在使用来自Apache集合库的TreeBidiMap。我想对double类型的值进行排序。

我的方法是检索值的集合使用:

Collection coll = themap.values();

这很正常。

主要问题:我现在想知道我如何转换/cast(不确定哪个是正确的)coll成一个列表,这样它就可以排序?

然后,我打算遍历排序的List对象,它应该是有序的,并使用themap. getkey (iterator.next())从TreeBidiMap (themap)中获得适当的键,其中迭代器将在double列表上。

Python 2文档说:

Built-in Functions: map(function, iterable, ...) Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel. If one iterable is shorter than another it is assumed to be extended with None items. If function is None, the identity function is assumed; if there are multiple arguments, map() returns a list consisting of tuples containing the corresponding items from all iterables (a kind of transpose operation). The iterable arguments may be a sequence or any iterable object; the result is always a list.

它在笛卡尔积中起什么作用呢?

content = map(tuple, array)

把一个元组放在那里有什么影响?我还注意到,如果没有map函数,输出是abc,有了它,输出是abc。

我想完全理解这个函数。参考定义也很难理解。太多花哨的绒毛。

如果我有一个集合,如集合<String> strs,我怎么能得到第一项?我可以调用一个迭代器,取它的第一个next(),然后丢弃迭代器。有没有更少浪费的方法呢?

我正在寻找一种方法将xlsx文件转换为Linux上的csv文件。

我不想使用PHP/Perl或类似的东西,因为我正在处理数百万行,所以我需要一些快速的东西。我在Ubuntu repos上找到了一个名为xls2csv的程序,但它只会转换xls (Office 2003)文件(我目前正在使用),但我需要对更新的Excel文件的支持。

什么好主意吗?

我在许多例子中看到,有时使用Seq,而其他时候使用List……

除了前者是Scala类型,而List来自Java之外,还有什么区别吗?

反转这个数组列表最简单的方法是什么?

ArrayList<Integer> aList = new ArrayList<>();

//Add elements to ArrayList object
aList.add("1");
aList.add("2");
aList.add("3");
aList.add("4");
aList.add("5");

while (aList.listIterator().hasPrevious())
  Log.d("reverse", "" + aList.listIterator().previous());

我有一个集合列表:

setlist = [s1,s2,s3...]

我想要s1∩s2∩s3…

我可以写一个函数,通过执行一系列成对的s1.intersection(s2),等等。

是否有推荐的、更好的或内置的方法?

如何将值列表添加到现有集?

Java中是否存在类似Map的对象,用于存储和访问键/值对,但可以返回键的有序列表和值的有序列表,这样键和值列表的顺序是相同的?

因此,作为代码解释,我正在寻找一些行为类似于我虚构的OrderedMap的东西:

OrderedMap<Integer, String> om = new OrderedMap<>();
om.put(0, "Zero");
om.put(7, "Seven");

String o = om.get(7); // o is "Seven"
List<Integer> keys = om.getKeys();
List<String> values = om.getValues();

for(int i = 0; i < keys.size(); i++)
{
    Integer key = keys.get(i);
    String value = values.get(i);
    Assert(om.get(key) == value);
}