Core Java | Different Methods for Formatting String and Format Specifiers

preview_player
Показать описание
Core Java | Different Methods for Formatting String and Format Specifiers
#corejava #tamilkaruvoolam #stringformat

Source Code:
class Employee{
private String name;
private Double salary;
public Employee(String name, Double salary) {
}
@Override
public String toString(){
return "Employee[Name: %s, Salary: %.2f]".formatted(name, salary);
//return "Employee[Name: "+name+", Salary: "+salary+"]";
}
}
public class EmployeeTest {
public static void main(String[] args) {
Employee emp = new Employee("Kumar", 123456.543);
/**
* String - %s
* Integer - %d
* Double / Float - %f / %.2f
* Boolean - %b
*/
}
}
Рекомендации по теме
visit shbcf.ru