Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
Spring @Value empty list as default

Is there a way to set an empty list as default value for a property in Spring, something like:

@Value("${my.list.of.strings :" + new ArrayList<>() + "}")
private List<String> myList;

Obviously not new ArrayList, but I need an empty list there instead.

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

After taking a look at SpEL specification and combined with @javaguy's answer I came up with this:

@Value("${my.list.of.strings:}#{T(java.util.Collections).emptyList()}")
private List<String> myList;
about 4 years ago · Santiago Trujillo Report

0

Actually, in the current Spring versions works just one symbol : with an empty defaultvalue.

The full example that I'm using:

@Value("${my.custom.prop.array:}")
private List<Integer> myList;

To be sure and safer I also adding init to the List variable:

@Value("${my.custom.prop.array:}")
private List<Integer> myList = new ArrayList<>();
about 4 years ago · Santiago Trujillo Report

0

@Value("#{T(java.util.Arrays).asList('${my.list.of.strings:}')}")
private List<String> myList;

works for me, using Spring 5.0.x (gives empty list, if your my.list.of.strings property is not configured in context)

afterwards you can easily do something like

CollectionUtils.isNotEmpty(myList)
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!