• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Map with Arraylist as value

 
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have files with names such as

address_change__customer_request__111.pdf
address_change__corres_in__111.pdf
address_change__signature_card__222.pdf
address_change__customer_request__222.pdf
address_change__corres_in__222.pdf

Double underscore (__), differnetiates differnet parts of the file name.
Part1 --> value before first __ (example, address_change)
Part2 --> value after first __ and before second__ (example, customer_request, corres_in)
Part3 --> value after second __ (example, 111, 222)

I am able to read the file names and get the values for Part1, Part2 and Part3.
The file names with similar Part3 need to be handled in the same way. Example, files 1 and 2, need to be handled differently from files 3,4 and 5.

So to distinguish files based on Part3, I want to create a datastructure such as
Map<String, <List<String>>

example,
The Map which has first key as 111 and value is an Arraylist containing address_change__customer_request__111.pdf and address_change__corres_in__111.pdf
Second key in the Map is 222 and value is an ArrayList containing values address_change__signature_card__222.pdf, address_change__customer_request__222.pdf and address_change__corres_in__222.pdf

Please let me know how can this be achieved.


Trying to do something like this

 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean you want to use one part of the String as a key to get a List<String> as the value and add the remainder of the String to the List?
You just need to make sure to put a new List<String> into the Map if it doesn't contain that particular key.

That's what you have to do. Go through the Map interface API documentation and all the functionality you need is there.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic