Use of Java's Collections.singletonList()? -


what use of collections.singletonlist() in java? (i understand returns list 1 element. why want have separate method that? how immutability play role here?)

are there special useful use-cases method, rather being convenience method?

the javadoc says this:

"returns immutable list containing specified object. returned list serializable."

you ask:

why want have separate method that?

as convenience ... save having write sequence of statements to:

  • create empty list object
  • add element it, and
  • wrap immutable wrapper.

are there special useful use-cases method, rather being convenience method?

clearly, there use-cases convenient use singletonlist method. don't know how (objectively) distinguish between ordinary use-case , "specially useful" 1 ...


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -