// String 배열 기준
// 1. size()
public static int size(String[] arr) {
return arr.length;
}
// 2. contains()
public static boolean contains(String[] arr, String element) {
for (int i = 0; i < size(arr); i++) {
if (arr[i].equals(element)) {
return true;
}
}
return false;
}
// 3. indexOf()
public static int indexOf(String[] arr, String element) {
for (int i = 0; i < size(arr); i++) {
if (arr[i].equals(element)) {
return i;
}
}
return -1;
}
// 4. lastIndexOf()
public static int lastIndexOf(String[] arr, String element) {
for (int i = size(arr) - 1; i >= 0; i--) {
if (arr[i].equals(element)) {
return i;
}
}
return -1;
}
// 5. add()
public static String[] add(String[] arr, String element) {
String[] temp = arr;
arr = new String[size(arr) + 1];
for (int i = 0; i < size(temp); i++) {
arr[i] = temp[i];
}
arr[size(arr) - 1] = element;
return arr;
}
// 6. add(index)
public static String[] add(String[] arr, int index, String element) {
if (!(index >= 0 && index < size(arr))) {
return arr;
}
String[] temp = arr;
arr = new String[size(arr) + 1];
for (int i = 0; i < index; i++) {
arr[i] = temp[i];
}
arr[index] = element;
for (int i = index + 1; i < arr.length; i++) {
arr[i] = temp[i - 1];
}
return arr;
}
// 7. removeByIndex()
public static String[] removeByIndex(String[] arr, int index) {
if (!(index >= 0 && index < size(arr))) {
return arr;
}
String[] temp = arr;
arr = new String[size(arr) - 1];
for (int i = 0; i < index; i++) {
arr[i] = temp[i];
}
for (int i = index; i < arr.length; i++) {
arr[i] = temp[i + 1];
}
return arr;
}
// 8. removeByElement()
public static String[] removeByElement(String[] arr, String element) {
return removeByIndex(arr, indexOf(arr, element));
}
// 1. size()
public static int size(Student[] arr) {
return arr.length;
}
// 2. contains()
public static boolean contains(Student[] arr, Student s) {
for (int i = 0; i < size(arr); i++) {
if (arr[i].equals(s)) {
return true;
}
}
return false;
}
// 3. indexOf()
public static int indexOf(Student[] arr, Student s) {
for (int i = 0; i < size(arr); i++) {
if (arr[i].equals(s)) {
return i;
}
}
return -1;
}
// 4. lastIndexOf()
public static int lastIndexOf(Student[] arr, Student s) {
for (int i = size(arr) - 1; i >= 0; i--) {
if (arr[i].equals(s)) {
return i;
}
}
return -1;
}
// 5. add()
public static Student[] add(Student[] arr, Student s) {
Student[] temp = arr;
arr = new Student[size(arr) + 1];
for (int i = 0; i < size(temp); i++) {
arr[i] = temp[i];
}
arr[size(arr) - 1] = s;
return arr;
}
// 6. add(index)
public static Student[] add(Student[] arr, int index, Student s) {
if (index >= 0 && index <= size(arr)) {
Student[] temp = arr;
arr = new Student[size(arr) + 1];
for (int i = 0; i < index; i++) {
arr[i] = temp[i];
}
arr[index] = s;
for (int i = index; i < size(temp); i++) {
arr[i + 1] = temp[i];
}
}
return arr;
}
// 7. removeByIndex()
public static Student[] removeByIndex(Student[] arr, int index) {
if (index >= 0 && index < size(arr)) {
Student[] temp = arr;
arr = new Student[size(arr) - 1];
for (int i = 0; i < index; i++) {
arr[i] = temp[i];
}
for (int i = index; i < size(arr); i++) {
arr[i] = temp[i + 1];
}
}
return arr;
}
// 8. removeByElement()
public static Student[] removeByElement(Student[] arr, Student s) {
return removeByIndex(arr, indexOf(arr, s));
}
}