Skip to main content

All Questions

Tagged with
6 votes
4 answers
6k views

Is "use "abc".equals(myString) instead of myString.equals("abc") to avoid null pointer exception" already problematic in terms of business logic?

I heard numerous times that when comparing Strings in Java, to avoid null pointer exception, we should use "abc".equals(myString) instead of myString.equals("abc"), but my question is, is this idea ...
ggrr's user avatar
  • 5,863
2 votes
3 answers
6k views

Can regexp be used to check for palindromes?

Can regexp pattern matching be used to check for palindromes within a given text in Java? My intuition is that in order to check for palindromes, we may need to remember the character that was parsed,...
GermanShepherd's user avatar
-6 votes
2 answers
341 views

Which piece of code is more efficient with respect to Time and Memory cost? [closed]

Code 1: private static int myCompare(String a, String b) { /* my version of the compareTo method from the String Java class */ int len1 = a.length(); int len2 = b.length(); if (...
Avid Programmer's user avatar