Skip to main content
Commonmark migration
Source Link

The String class contains a contains method to check the @ symbol, and you can simply check for null with a != null call:

public static void main(String[] args) { String a = "should be false"; String b = "should be @true"; String c = null; System.out.println(checkString(a)); System.out.println(checkString(b)); System.out.println(checkString(c)); } static boolean checkString(String str) { return str != null && str.contains("@"); } 

Output:

false

 

true

 

false

The String class contains a contains method to check the @ symbol, and you can simply check for null with a != null call:

public static void main(String[] args) { String a = "should be false"; String b = "should be @true"; String c = null; System.out.println(checkString(a)); System.out.println(checkString(b)); System.out.println(checkString(c)); } static boolean checkString(String str) { return str != null && str.contains("@"); } 

Output:

false

 

true

 

false

The String class contains a contains method to check the @ symbol, and you can simply check for null with a != null call:

public static void main(String[] args) { String a = "should be false"; String b = "should be @true"; String c = null; System.out.println(checkString(a)); System.out.println(checkString(b)); System.out.println(checkString(c)); } static boolean checkString(String str) { return str != null && str.contains("@"); } 

Output:

false

true

false

Source Link
achAmháin
  • 4.3k
  • 4
  • 20
  • 42

The String class contains a contains method to check the @ symbol, and you can simply check for null with a != null call:

public static void main(String[] args) { String a = "should be false"; String b = "should be @true"; String c = null; System.out.println(checkString(a)); System.out.println(checkString(b)); System.out.println(checkString(c)); } static boolean checkString(String str) { return str != null && str.contains("@"); } 

Output:

false

true

false