I want to convert the following code to use Lambdas and Streams and/or any other Java 8 functionality.
I am new to Java 8 and tried converting the below code to Java 8 but couldn't find any function like 'forEach' that would fit my scenario.
private String getMacAddress() {
InetAddress ip;
try {
ip = InetAddress.getLocalHost();
logger.log(LogLevel.LEVEL_INFO,"Current IP address : " + ip.getHostAddress());
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
logger.log(LogLevel.LEVEL_INFO,"Current MAC address : ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
return sb.toString();
} catch (UnknownHostException e) {
logger.log(LogLevel.LEVEL_ERROR,e.getMessage());
} catch (SocketException e){
logger.log(LogLevel.LEVEL_ERROR,e.getMessage());
}
}