Require Maven dependency in project pom.xml file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!-- Add this Maven dependecy in your pom file -->
<dependencies>
<!-- https://mvnrepository.com/artifact/com.github.javadev/underscore -->
<dependency>
<groupId>com.github.javadev</groupId>
<artifactId>underscore</artifactId>
<version>1.69</version>
</dependency>
</dependencies>
<!-- Add this Maven dependecy in your pom file --> <dependencies> <!-- https://mvnrepository.com/artifact/com.github.javadev/underscore --> <dependency> <groupId>com.github.javadev</groupId> <artifactId>underscore</artifactId> <version>1.69</version> </dependency> </dependencies>
<!-- Add this Maven dependecy in your pom file -->
<dependencies>
    <!-- https://mvnrepository.com/artifact/com.github.javadev/underscore -->
    <dependency>
        <groupId>com.github.javadev</groupId>
        <artifactId>underscore</artifactId>
        <version>1.69</version>
    </dependency>
</dependencies>

Java code with explainer comments:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
//1. require import statements
import com.github.underscore.lodash.U;
import java.util.LinkedHashMap;
import java.util.Map;
//...
//2. create Map object name 'map'
Map<String, Object> map = new LinkedHashMap<>();
//3. enter "key"(String), "value"(Object) pair
map.put("id", "1");
map.put("name", "jorge");
//4. display map value in console
System.out.println("map: " + map);
//5. convert map to xml and assign to String 'xml' variable
String xml = U.toXml(map);
//6. display xml1 value in console
System.out.println("xml: " + xml);
//1. require import statements import com.github.underscore.lodash.U; import java.util.LinkedHashMap; import java.util.Map; //... //2. create Map object name 'map' Map<String, Object> map = new LinkedHashMap<>(); //3. enter "key"(String), "value"(Object) pair map.put("id", "1"); map.put("name", "jorge"); //4. display map value in console System.out.println("map: " + map); //5. convert map to xml and assign to String 'xml' variable String xml = U.toXml(map); //6. display xml1 value in console System.out.println("xml: " + xml);
//1. require import statements
import com.github.underscore.lodash.U;
import java.util.LinkedHashMap;
import java.util.Map;
//...

//2. create Map object name 'map'
Map<String, Object> map = new LinkedHashMap<>();

//3. enter "key"(String), "value"(Object) pair
map.put("id", "1"); 
map.put("name", "jorge");

//4. display map value in console
System.out.println("map: " + map);

//5. convert map to xml and assign to String 'xml' variable
String xml = U.toXml(map);

//6. display xml1 value in console
System.out.println("xml: " + xml);

console output:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
map: {id=1, name=jorge}
xml1: <?xml version="1.0" encoding="UTF-8"?>
<root>
<id>1</id>
<name>jorge</name>
</root>
map: {id=1, name=jorge} xml1: <?xml version="1.0" encoding="UTF-8"?> <root> <id>1</id> <name>jorge</name> </root>
map: {id=1, name=jorge}
xml1: <?xml version="1.0" encoding="UTF-8"?>
<root>
  <id>1</id>
  <name>jorge</name>
</root>