1

I'm trying to declare a String array within a method invocation, like so:

if (emailYaml.keySet().containsAll(new String[]{"mailto","subject","text"}))

I'm not entirely sure if this is the best approach in any case (i'm pretty new to programming), but in any case Eclipse tells me:

The method containsAll(Collection<?>) in the type Set<String> is not applicable for the arguments (String[])

Could anyone help with a solution?

Many thanks

1
  • Arrays.asList("mailto","subject","text") Commented Feb 21, 2013 at 15:48

3 Answers 3

4

An array isn't a subtype of Collection. Convert it to a List for example, before passing it to containsAll:

.containsAll(Arrays.asList(new String[] {"mailto", "subject", "text"}))

Or even simplier, since asList takes a vararg as parameter:

.containsAll(Arrays.asList("mailto", "subject", "text"))
Sign up to request clarification or add additional context in comments.

Comments

0

containsAll() expects a Collection and you are passing an array, thus your compiler complains.

if (emailYaml.keySet().containsAll(Arrays.asList(new String[]
  {"mailto","subject","text"})))

1 Comment

easier: if (emailYaml.keySet().containsAll(Arrays.asList("mailto","subject","text")))
0

Contains all accepts a collection.

From the docs:

containsAll(Collection<?> c) 

Try this insead:

if (emailYaml.keySet().containsAll(Arrays.asList("mailto","subject","text"))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.