Configuration Reader in Java: Explanation & Practice
Parse key=value configuration format
Problem summary
Parse a configuration string in key=value format and retrieve values by key.
Starter code
import java.util.*;
public class Main {
public static void main(String[] args) {
String config = "host=localhost\nport=8080\nprotocol=https";
// Parse config and print values
// Print: host=localhost, port=8080, protocol=https
}
}Expected output and test cases
- Config parsed and displayed
host=localhost, port=8080, protocol=https
Hints
- Split by newline
- Split each line by =
- Store in Map for easy access
Related File I/O exercises
Practice all File I/O exercises · Run this idea in the Java compiler