-1

how can I replace words using map that populate the value in properties file?

I have this code to load the properties file:

Properties propertiesSlang = new Properties();
FileInputStream fileReadSlang = new FileInputStream(slang);
propertiesSlang.load(fileReadSlang);
System.out.println(propertiesSlang);
Map<String, String> replacements = new HashMap<String, String>((Map)propertiesSlang);

I have many slang tokens that I have to replace, how can I replace the slang tokens?

MrSimpleMind
  • 7,890
  • 3
  • 40
  • 45

1 Answers1

0

If you want to replace words in an array, use a simple iteration:

String[] words;
//...
for (int i = 0; i < words.length; i ++) {
    String word = words[i];
    String rep = replacements.get(word);
    if (rep != null) {
        words[i] = rep;
    }
}
pkalinow
  • 1,619
  • 1
  • 17
  • 43