Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Dauda Ainoo
Added: Apr 28, 2020 8:28 PM
Views: 131
Tags: no tags
  1. public static void main(String[] args) {
  2.     User user1 = new User.UserBuilder("Lokesh", "Gupta")
  3.     .age(30)
  4.     .phone("1234567")
  5.     .address("Fake address 1234")
  6.     .build();
  7.  
  8.     System.out.println(user1);
  9.  
  10.     User user2 = new User.UserBuilder("Jack", "Reacher")
  11.     .age(40)
  12.     .phone("5655")
  13.     //no address
  14.     .build();
  15.  
  16.     System.out.println(user2);
  17.  
  18.     User user3 = new User.UserBuilder("Super", "Man")
  19.     //No age
  20.     //No phone
  21.     //no address
  22.     .build();
  23.  
  24.     System.out.println(user3);
  25. }
  26.  
  27. Output:
  28.  
  29. User: Lokesh, Gupta, 30, 1234567, Fake address 1234
  30. User: Jack, Reacher, 40, 5655, null
  31. User: Super, Man, 0, null, null