English 中文(简体)
接受收集方法的单一要素
原标题:Pass Single Element to Method that Accepts a Collection

有一种接受收集的方法。 我需要把一个因素纳入这种方法。 这样做的最佳方式是什么? 我应当使用哪一种收集方法?

最佳回答

java.util.Collections.singleton()

问题回答

根据我的理解,你有这样的方法:

public void someMethod(Collection c)

并且,你们需要把一个单一要素交给它(即MyObject)。

这里有两个选择:

  1. 编制清单,加上MyObject,然后通过清单。

  2. 如果可能的话,使用多吗? - 建立新办法,将MyObject作为参数:

    公共领域 方法(MyObject obj);





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签