Core Java | Different Methods for Formatting String and Format Specifiers

Published: 26 September 2022
on channel: Learn with Professor
822
like

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) {
this.name = name;
this.salary = salary;
}
@Override
public String toString(){
return "Employee[Name: %s, Salary: %.2f]".formatted(name, salary);
//return String.format("Employee[Name: %s, Salary: %.2f]", name, salary);
//return "Employee[Name: "+name+", Salary: "+salary+"]";
}
}
public class EmployeeTest {
public static void main(String[] args) {
Employee emp = new Employee("Kumar", 123456.543);
System.out.println(emp.toString());
/**
String - %s
Integer - %d
Double / Float - %f / %.2f
Boolean - %b
*/
System.out.format("Employee Salary is %.2f", 7452754.5067);
}
}


On this page of the site you can watch the video online Core Java | Different Methods for Formatting String and Format Specifiers with a duration of hours minute second in good quality, which was uploaded by the user Learn with Professor 26 September 2022, share the link with friends and acquaintances, this video has already been watched 822 times on youtube and it was liked by like viewers. Enjoy your viewing!