简体   繁体   中英

Alternate to String.join to concatenate

I am inserting a key value pair to hashmap in the below code.

HashMap<String, String> result = new HashMap<String, String>();
    result.put("Description", "true";
    result.put("System Menu Program", "false");
    result.put("User ID Code", "false");
    result.put("User ID Version", "true");

And i am trying to iterate the result to be printed by joining multiple output string . currently i am using String.join to join the results which contains false as value but the problem i am facing here is i need to use any alternate to String.join because String.join method has been released in java 1.8 but our server is using 1.6 is there a alternate way to replace this below function

List<String> a1 = new ArrayList<String>();
    for (String key : result.keySet()) {
       if (result.get(key).contains("false")){
           a1.add(result.get(key));
           finalResult = String.join(" // ", a1 );
       }
    }
    System.out.println(finalResult);
    return finalResult;

Take a look at Apache common's StringUtils.join , which internally iterates and concatenate.

Alternatively, have your own implementation that will iterate and join.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM