0

Why does converting Enumeration object to List more than once result to empty list after the first one?

Here is an example:

List<String> strings = Arrays.asList("page.info1", "page.info2");
Enumeration<String> stringEnumeration = Collections.enumeration(strings);
List<String> se1 = Collections.list(stringEnumeration);
List<String> se2 = Collections.list(stringEnumeration);
System.out.println(se1 + "|" + se2);

List se2 is empty.

[page.info1, page.info2]|[]

Why is that?

Thanks.

Julez
  • 1,010
  • 22
  • 44
  • 1
    Probaly because `stringEnumeration` is exhausted after `set1` is created. – ernest_k Jul 20 '18 at 09:46
  • 1
    Is there a reason you're using the incredibly outdated `Enumeration` class? – Kayaman Jul 20 '18 at 09:47
  • Yes, @Kayaman. To read properties keys in Liferay: `Enumeration propertiesKeysEnumeration = this.getResourceBundle(request.getLocale()).getKeys();` – Julez Jul 20 '18 at 09:57

0 Answers0