-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP06.java
More file actions
35 lines (29 loc) · 781 Bytes
/
P06.java
File metadata and controls
35 lines (29 loc) · 781 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
31
32
33
34
35
package lists;
import java.util.List;
import java.util.NoSuchElementException;
/**
* Class for String manipulation.
* Find the palindrome
*/
public final class P06 {
private P06() {
}
/**
* Find if the list of items is palindrome or not.
*
* @param list list of items
* @param <T> type of item in input list
* @return true if palindrome, false it not
*/
public static <T> boolean isPalindrome(final List<T> list) {
if (list.isEmpty()) {
throw new NoSuchElementException("List is empty");
}
for (int i = 0, j = list.size() - 1; i < list.size() / 2; i++, j--) {
if (list.get(i) != list.get(j)) {
return false;
}
}
return true;
}
}