• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Anyone know How to solve this basic problem?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Outline
-------
My java program saves the words from ten text files into a tree map called frequencyData (it also records the frequency of each word).

There is a for loop to read each document file and the names of each file are stored in a string array (Docs).

Question
--------
How can I change the program so that a tree map is made for each document file? [I'm guessing a will have to create a new tree map within the for loop.]

Also, How do I determine the name of each new tree map? (eg. frequencyData1, frequencyData2....frequencyData10)





 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This "how do I determine the variable name" thing is a fundamental milestone that all thinking programmers get to -- some earlier, some later. The fact that you see the problem, and are trying to find a solution, is a good sign!

In any case, the important thing is that there is no solution, at least not the kind you're looking for. You can't invent variables at runtime. The compiler has to know the name of a variable, which means you have to know the name while you're typing the program -- and since you don't, for example, know how many files will be read, you don't know the names.

Now, the good news is that all it takes is looking at the problem from a slightly different angle, and I think when I say this you will slap your forehead at its obviousness: the solution to the "how do I make up variable names at runtime" question is always "use a Collection." Use, in your case, a List of Maps -- or perhaps a Map of Maps, with the filenames as keys and the word maps as the values. Then each Map has a "name" in the form of its key in the map.
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic