Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. getLength("Hallo");
  2. System.out.println(getLength("Hallo")); // 5
  3. System.out.println(getLength(null)); // -1
  4. System.out.println(getLength("")); // 0
  5. System.out.println("=========================");
  6.  
  7. System.out.println((getLength(new String[0])));
  8. System.out.println((getLength(new String[] { "a", "b" })));
  9.  
  10. }
  11.  
  12. private static int getLength(String... checkString) {
  13.  
  14. if (checkString == null || checkString.length == 0) {
  15. return -1;
  16.  
  17. } else if (checkString.length == 1) {
  18. return checkString[0].length();
  19. } else {
  20. return checkString.length;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement