January 2018
Intermediate to advanced
434 pages
14h 1m
English
Kotlin packs great features with commonly used data type String. One of the really cool features is String templates. This feature allows Strings to contain template expression.
In Java, you had to use StrSubstitutor (https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StrSubstitutor.html) and a map to go with it. A template expression in Java will look as follows:
Map<String, String> valuesMap = new HashMap<String, String>();valuesMap.put("city", "Paris");valuesMap.put("monument", "Eiffel Tower");String templateString ="Enjoyed ${monument} in ${city}.";StrSubstitutorsub=newStrSubstitutor(valuesMap);String resolvedString =sub.replace(templateString);
Kotlin eases out ...
Read now
Unlock full access