Talend Data Types - Convert STRING data type to other data types
In Talend's tMap component, you can convert a String data type to several other data types. Here's a table showing the conversions and examples:
Target Data Type
Conversion Method
Example
Boolean
Boolean.valueOf(string)
Boolean.valueOf("true") results in true
Byte
Byte.valueOf(string)
Byte.valueOf("123") results in 123
Short
Short.valueOf(string)
Short.valueOf("123") results in 123
Integer
Integer.valueOf(string)
Integer.valueOf("123") results in 123
Long
Long.valueOf(string)
Long.valueOf("123") results in 123L
Float
Float.valueOf(string)
Float.valueOf("123.45") results in 123.45f
Double
Double.valueOf(string)
Double.valueOf("123.45") results in 123.45d
BigDecimal
new BigDecimal(string)
new BigDecimal("123.45") results in 123.45
Date
TalendDate.parseDate("yyyy-MM-dd", string)
TalendDate.parseDate("yyyy-MM-dd", "2023-06-17") results in June 17, 2023
Please note that when converting a string to a date, you need to specify the date format. In the example provided, the date format is "yyyy-MM-dd". If your date string is in a different format, you'll need to adjust the format string accordingly. Also, these conversions will throw a NumberFormatException or ParseException if the string cannot be parsed to the target data type.