-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringUtils.java
More file actions
30 lines (27 loc) · 694 Bytes
/
StringUtils.java
File metadata and controls
30 lines (27 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class StringUtils {
/**
* If string is Palindrome the this function will return true else false
* @param input
* @return
*/
public static boolean isPalindrome(String input) {
if (input == null) {
throw new IllegalArgumentException("Input String must be not null");
}
char[] word = input.toCharArray();
boolean match = true;
int forward = 0;
int backward = word.length - 1;
while ((backward > forward) && match) {
if (word[forward] != word[backward]) {
match = false;
}
++forward;
--backward;
}
return match;
}
public static void main(String[] args) {
System.out.println( isPalindrome("12121"));
}
}