Line | |
---|
1 | package org.apollo.util;
|
---|
2 |
|
---|
3 | public final class StringEx {
|
---|
4 |
|
---|
5 | private StringEx() {}
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * This is a string equals method that handles null pointers
|
---|
9 | *
|
---|
10 | * Notes: Javas thread-pool system doesn't mean that a string cannot only
|
---|
11 | * be created once in java ... one can explicity use the new operater for
|
---|
12 | * a string to be duplicated... thus using the "==" operater is to risky.
|
---|
13 | * Especially since many methods such as substring uses the new operator!
|
---|
14 | *
|
---|
15 | * @param str1
|
---|
16 | *
|
---|
17 | * @param str2
|
---|
18 | *
|
---|
19 | * @return
|
---|
20 | */
|
---|
21 | public static boolean equals(String str1, String str2) {
|
---|
22 |
|
---|
23 | if (str1 == str2) return true; // they both null or same ref?
|
---|
24 |
|
---|
25 | else if (str1 == null) return false; // one is null
|
---|
26 |
|
---|
27 | else if (str2 == null) return false; // one is null
|
---|
28 |
|
---|
29 | return str1.equals(str2); // Evaluate..
|
---|
30 |
|
---|
31 | }
|
---|
32 |
|
---|
33 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.