From adc8fa09b4fa2f50453f4b5ec803ad9fd5e2e9d9 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Wed, 3 Nov 2021 22:39:27 -0400 Subject: [PATCH 1/5] lab --- .../zipcodewilmington/StringArrayUtils.java | 59 +++++++++++++++++-- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index 4bcce66..32f50a2 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -1,5 +1,7 @@ package com.zipcodewilmington; +import java.util.Arrays; + /** * Created by leon on 1/29/18. */ @@ -9,6 +11,7 @@ public class StringArrayUtils { * @return first element of specified array */ // TODO public static String getFirstElement(String[] array) { + return array[0]; } @@ -17,6 +20,7 @@ public static String getFirstElement(String[] array) { * @return second element in specified array */ public static String getSecondElement(String[] array) { + return array[1]; } @@ -25,7 +29,14 @@ public static String getSecondElement(String[] array) { * @return last element in specified array */ // TODO public static String getLastElement(String[] array) { - return null; + + // get length of array + int lengthOfArray = array.length; + + // index is length of array - 1 + int lastIndex = lengthOfArray - 1; + // return array at index + return array[lastIndex]; } /** @@ -33,7 +44,12 @@ public static String getLastElement(String[] array) { * @return second to last element in specified array */ // TODO public static String getSecondToLastElement(String[] array) { - return null; + // get length of array + int lengthOfArray = array.length; + // correct index is lengthOfArray - 2 + int index = lengthOfArray - 2; + // return array at index + return array[index]; } /** @@ -42,7 +58,17 @@ public static String getSecondToLastElement(String[] array) { * @return true if the array contains the specified `value` */ // TODO public static boolean contains(String[] array, String value) { - return false; + int count = 0; + // go through each word in array + for (String word : array) { + // check if word is the same as value + // if word == value + if (word == value) { + return true; + } + // return true + } + return true; } /** @@ -50,7 +76,14 @@ public static boolean contains(String[] array, String value) { * @return an array with identical contents in reverse order */ // TODO public static String[] reverse(String[] array) { - return null; + // declaring new String[] and setting length + String[] result = new String[array.length]; // with empty slots + + for (int i = 0; i < array.length; i++) { + result[result.length-1-i] = array[i]; + + } + return result; } /** @@ -58,7 +91,11 @@ public static String[] reverse(String[] array) { * @return true if the order of the array is the same backwards and forwards */ // TODO public static boolean isPalindromic(String[] array) { - return false; + String[] reversed = reverse(array); + if (Arrays.equals(reversed, array)) { // arrays.equals is an array util to compare arrays ( pass in arrays) + return true; + } + return false; } /** @@ -66,7 +103,7 @@ public static boolean isPalindromic(String[] array) { * @return true if each letter in the alphabet has been used in the array */ // TODO public static boolean isPangramic(String[] array) { - return false; + } /** @@ -75,6 +112,16 @@ public static boolean isPangramic(String[] array) { * @return number of occurrences the specified `value` has occurred */ // TODO public static int getNumberOfOccurrences(String[] array, String value) { + + + + + + + + + + return 0; } From 58aa7e611f5e3637cddaa3d5942dbafee98b0b3c Mon Sep 17 00:00:00 2001 From: Ellis John Date: Fri, 5 Nov 2021 20:00:39 -0400 Subject: [PATCH 2/5] lab --- .../zipcodewilmington/StringArrayUtils.java | 90 ++++++++++++++++--- 1 file changed, 77 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index 32f50a2..4596a43 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -1,5 +1,7 @@ package com.zipcodewilmington; +import com.sun.xml.internal.fastinfoset.util.StringArray; + import java.util.Arrays; /** @@ -80,7 +82,7 @@ public static String[] reverse(String[] array) { String[] result = new String[array.length]; // with empty slots for (int i = 0; i < array.length; i++) { - result[result.length-1-i] = array[i]; + result[result.length - 1 - i] = array[i]; } return result; @@ -91,11 +93,11 @@ public static String[] reverse(String[] array) { * @return true if the order of the array is the same backwards and forwards */ // TODO public static boolean isPalindromic(String[] array) { - String[] reversed = reverse(array); + String[] reversed = reverse(array); // just using above method to reverse String[] array if (Arrays.equals(reversed, array)) { // arrays.equals is an array util to compare arrays ( pass in arrays) return true; } - return false; + return false; } /** @@ -104,8 +106,26 @@ public static boolean isPalindromic(String[] array) { */ // TODO public static boolean isPangramic(String[] array) { + // needs to return a T/F statement + + String newString = Arrays.toString(array); // converted array to string + + if (newString.length() < 26) { // if this string is less than 26, has to be false + return false; + } + + // created a new array with whole alphabet + String[] alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; + + for (int i = 0; i < array.length; i++) { // for loop to iterate through array + if (!newString.contains(alphabet[i])) { // if newString does not contain alphabet at i + return false; // return false + } + } + return true; // otherwise, return true } + /** * @param array array of String objects * @param value value to check array for @@ -113,16 +133,22 @@ public static boolean isPangramic(String[] array) { */ // TODO public static int getNumberOfOccurrences(String[] array, String value) { + // declare variables we'll use, counter and i + Integer counter = 0; + int i; + // set up for loop to start at i, end at the end of array, and i increases by one each time + for (i = 0; i < array.length; i++) { + // set up if statement to compare if value equals the element each time + if (value.equals(array[i])) { + // increase counter by one if value and array[i] are the same + counter = counter + 1; + } + } + // return the final count + return counter; - - - - - - - return 0; } /** @@ -130,8 +156,21 @@ public static int getNumberOfOccurrences(String[] array, String value) { * @param valueToRemove value to remove from array * @return array with identical contents excluding values of `value` */ // TODO - public static String[] removeValue(String[] array, String valueToRemove) { - return null; + public static String[] removeValue(String[] array, String valueToRemove) { ////// TODO please revisit + + + // convert String[] to a string + String newString = Arrays.toString(array); + // since both are now strings, we can .replace and replace valueToRemove with "" (that is, nothing) + // declared and assigned to new string stringWithValuesRemoved + String stringWithValueRemoved = newString.replace(valueToRemove, ""); + // use .split method to split the elements on a space " ", to make array of each word + // declare and assign as a new variable arrayWithValueRemoved + String[] arrayWithValueRemoved = stringWithValueRemoved.split(" "); + + return arrayWithValueRemoved; + + } /** @@ -139,7 +178,19 @@ public static String[] removeValue(String[] array, String valueToRemove) { * @return array of Strings with consecutive duplicates removes */ // TODO public static String[] removeConsecutiveDuplicates(String[] array) { + String[] removedDuplicatesArray = new String[5]; + int arrayLength = array.length; + int counter = 0; + + for (int i = 0; i < arrayLength; i++) { + if (array[i] == array[i + 1]) { + counter++; + array[counter] = array[i]; + } + } return null; + + } /** @@ -147,7 +198,20 @@ public static String[] removeConsecutiveDuplicates(String[] array) { * @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings */ // TODO public static String[] packConsecutiveDuplicates(String[] array) { - return null; + // string to hold the position at 1 + String duplicates = array[0]; + + for (int i=1; i< array.length; i++) { + // if we are going through the array and we encounter a lettter thats is same to letter ebfore + if(array[i].equals(array[i-1])) { + duplicates = duplicates + array[i]; + } + else { + duplicates = duplicates + " " + array[i]; + } + System.out.println("duplicate " + duplicates); + } + return duplicates.split(" "); } From d0922da2a8458f305d99ebdbd3ee09be617af8d3 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Fri, 5 Nov 2021 21:36:20 -0400 Subject: [PATCH 3/5] lab --- .../zipcodewilmington/StringArrayUtils.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index 4596a43..74215a2 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -2,7 +2,9 @@ import com.sun.xml.internal.fastinfoset.util.StringArray; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; /** * Created by leon on 1/29/18. @@ -156,19 +158,18 @@ public static int getNumberOfOccurrences(String[] array, String value) { * @param valueToRemove value to remove from array * @return array with identical contents excluding values of `value` */ // TODO - public static String[] removeValue(String[] array, String valueToRemove) { ////// TODO please revisit + public static String[] removeValue(String[] array, String valueToRemove) { ////// + // with lists you dont have to declare a size, they can grow and shrink as needed + List stringList = new ArrayList(); - // convert String[] to a string - String newString = Arrays.toString(array); - // since both are now strings, we can .replace and replace valueToRemove with "" (that is, nothing) - // declared and assigned to new string stringWithValuesRemoved - String stringWithValueRemoved = newString.replace(valueToRemove, ""); - // use .split method to split the elements on a space " ", to make array of each word - // declare and assign as a new variable arrayWithValueRemoved - String[] arrayWithValueRemoved = stringWithValueRemoved.split(" "); + for (int i = 0; i < array.length; i++) { + if (!array[i].equals(valueToRemove)) { // if array at i is the same as the valueToRemove + stringList.add(array[i]); // if so, then add array of i to stringList + } - return arrayWithValueRemoved; + } + return stringList.toArray(new String[0]); // return our stringList, (new String[0]) is signifying that it will be a String array } @@ -178,17 +179,17 @@ public static String[] removeValue(String[] array, String valueToRemove) { /// * @return array of Strings with consecutive duplicates removes */ // TODO public static String[] removeConsecutiveDuplicates(String[] array) { - String[] removedDuplicatesArray = new String[5]; - int arrayLength = array.length; - int counter = 0; - - for (int i = 0; i < arrayLength; i++) { - if (array[i] == array[i + 1]) { - counter++; - array[counter] = array[i]; + List result = new ArrayList(); // created new list named result -- its always easier to use a list + + for (int i = 0; i < array.length - 1; i++) { + if (!array[i].equals(array[i + 1])) { + result.add(array[i]); } } - return null; + if (!array[array.length - 1].equals(result.get(result.size() - 1))) { /// if array at last index is the same as the last element in the list + result.add(array[array.length - 1]); /// add to result list the last element + } + return result.toArray(new String[0]); } @@ -201,12 +202,11 @@ public static String[] packConsecutiveDuplicates(String[] array) { // string to hold the position at 1 String duplicates = array[0]; - for (int i=1; i< array.length; i++) { - // if we are going through the array and we encounter a lettter thats is same to letter ebfore - if(array[i].equals(array[i-1])) { + for (int i = 1; i < array.length; i++) { + // if we are going through the array and we encounter a lettter thats is same to letter before + if (array[i].equals(array[i - 1])) { duplicates = duplicates + array[i]; - } - else { + } else { duplicates = duplicates + " " + array[i]; } System.out.println("duplicate " + duplicates); From b807c7f6319162c5334838436e3fbb542718b973 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Mon, 6 Dec 2021 21:38:25 -0500 Subject: [PATCH 4/5] more --- pom.xml | 12 ++ .../zipcodewilmington/StringArrayUtils.java | 141 +++++++++++++----- 2 files changed, 113 insertions(+), 40 deletions(-) diff --git a/pom.xml b/pom.xml index d10c35e..4d4515a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ com.zipcodewilmington.labs arrayutils 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + junit diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index 74215a2..ad0acdb 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -1,9 +1,11 @@ package com.zipcodewilmington; +import com.sun.tools.javac.util.ArrayUtils; import com.sun.xml.internal.fastinfoset.util.StringArray; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -15,7 +17,7 @@ public class StringArrayUtils { * @return first element of specified array */ // TODO public static String getFirstElement(String[] array) { - + // using index 0 to access first element return array[0]; } @@ -24,7 +26,7 @@ public static String getFirstElement(String[] array) { * @return second element in specified array */ public static String getSecondElement(String[] array) { - + // using index 1 to access second element return array[1]; } @@ -62,17 +64,35 @@ public static String getSecondToLastElement(String[] array) { * @return true if the array contains the specified `value` */ // TODO public static boolean contains(String[] array, String value) { - int count = 0; - // go through each word in array - for (String word : array) { - // check if word is the same as value - // if word == value - if (word == value) { - return true; - } - // return true - } - return true; + + // done using streams + + boolean contains = Arrays.stream(array).anyMatch(value::equals); + + return contains; + + + + + + + + + + + + //// int count = 0; // this counter IS NOT necessary. needs to return boolean value, not a count of something +// +// // go through each word in array +// for (String word : array) { +// // check if word is the same as value +// // if word == value +// if (word == value) { +//// return true; // this is unnecessary as well +// } +// +// } +// return true; // placing the return outside the loop } /** @@ -80,10 +100,17 @@ public static boolean contains(String[] array, String value) { * @return an array with identical contents in reverse order */ // TODO public static String[] reverse(String[] array) { - // declaring new String[] and setting length + + + // declaring new String[] "result" and setting length String[] result = new String[array.length]; // with empty slots - for (int i = 0; i < array.length; i++) { + for (int i = 0; i < array.length; i++) { // loop through array + // we want to add to result, the current character at i. so, this is using index. + // result.length is the length of the array. -i will correspond to i. + // for example, if array is at index 2, then -i will be -2 + // this means that it will be the length of the array -2 (2 elements in from end) + // so the first element goes to last spot in result, second to second to last spot, third to third to last, etc result[result.length - 1 - i] = array[i]; } @@ -96,10 +123,12 @@ public static String[] reverse(String[] array) { */ // TODO public static boolean isPalindromic(String[] array) { String[] reversed = reverse(array); // just using above method to reverse String[] array - if (Arrays.equals(reversed, array)) { // arrays.equals is an array util to compare arrays ( pass in arrays) - return true; + // creates a new reversed array + if (Arrays.equals(reversed, array)) { // arrays.equals is an array util to compare arrays (pass in arrays) + // if statement comparing both arrays using Arrays.equals + return true; // return true if theyre equal } - return false; + return false; // return false if not true. } /** @@ -108,23 +137,27 @@ public static boolean isPalindromic(String[] array) { */ // TODO public static boolean isPangramic(String[] array) { - // needs to return a T/F statement + // needs to return a boolean T/F statement String newString = Arrays.toString(array); // converted array to string + // Arrays.toString util to make array into string - if (newString.length() < 26) { // if this string is less than 26, has to be false - return false; - } + if (newString.length() < 26) { // if this string is less than 26, has to be false + // this is the obvious, if its less than 26 letters, its clearly false + return false; // sometimes its best to knock out the obvious things first + } // this is placed above the loop, not a part of the below operation - // created a new array with whole alphabet + // created a new array with whole alphabet, so we can use it to compare String[] alphabet = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; - for (int i = 0; i < array.length; i++) { // for loop to iterate through array - if (!newString.contains(alphabet[i])) { // if newString does not contain alphabet at i + for (int i = 0; i < array.length; i++) { // for loop to iterate through array + if (!newString.contains(alphabet[i])) { // if newString DOES NOT contain alphabet at element i + // this is basically the opposite if if it contains the letter return true + // doing it this way continues to rule out more cases return false; // return false } } - return true; // otherwise, return true + return true; // otherwise, return true } @@ -136,8 +169,10 @@ public static boolean isPangramic(String[] array) { public static int getNumberOfOccurrences(String[] array, String value) { // declare variables we'll use, counter and i + // wants us to return an int, so thats why we have counter variable Integer counter = 0; - int i; + int i; // we could also simply declare and initializa the variable i in the first part of the for loop + // set up for loop to start at i, end at the end of array, and i increases by one each time for (i = 0; i < array.length; i++) { // set up if statement to compare if value equals the element each time @@ -147,7 +182,9 @@ public static int getNumberOfOccurrences(String[] array, String value) { } } - // return the final count + // return the final count -- this is returned OUTSIDE the loop + // returning this inside the loop will not work because as soon as it returns the loop stops + // ie it would stop looping after the first loop return counter; @@ -161,15 +198,20 @@ public static int getNumberOfOccurrences(String[] array, String value) { public static String[] removeValue(String[] array, String valueToRemove) { ////// // with lists you dont have to declare a size, they can grow and shrink as needed + // https://www.dummies.com/programming/java/use-array-lists-in-java/ + // List nameOfList = new ArrayList<>(); is the general syntax for creation + List stringList = new ArrayList(); - for (int i = 0; i < array.length; i++) { - if (!array[i].equals(valueToRemove)) { // if array at i is the same as the valueToRemove - stringList.add(array[i]); // if so, then add array of i to stringList + for (int i = 0; i < array.length; i++) { // for loop to loop through array + if (!array[i].equals(valueToRemove)) { // if array at i is NOT the same as the valueToRemove + stringList.add(array[i]); // if so, then add array of i to our stringList } } - return stringList.toArray(new String[0]); // return our stringList, (new String[0]) is signifying that it will be a String array + return stringList.toArray(new String[0]); // return our stringList, (new String[0]) is signifying... + // that it will be a String array + // we want to return a String[] } @@ -179,17 +221,23 @@ public static String[] removeValue(String[] array, String valueToRemove) { /// * @return array of Strings with consecutive duplicates removes */ // TODO public static String[] removeConsecutiveDuplicates(String[] array) { - List result = new ArrayList(); // created new list named result -- its always easier to use a list + List result = new ArrayList(); // created new list named result -- its always... + // easier to use a list - for (int i = 0; i < array.length - 1; i++) { - if (!array[i].equals(array[i + 1])) { - result.add(array[i]); + for (int i = 0; i < array.length - 1; i++) { // for loop set up + if (!array[i].equals(array[i + 1])) { // if theyre do not equal, throw that element into... + // our result list that we created + result.add(array[i]); // list.add(value); is the general syntax to add value to list } } - if (!array[array.length - 1].equals(result.get(result.size() - 1))) { /// if array at last index is the same as the last element in the list - result.add(array[array.length - 1]); /// add to result list the last element + + // https://www.geeksforgeeks.org/list-get-method-in-java-with-examples/ + // this link is for the .get method seen below + if (!array[array.length - 1].equals(result.get(result.size() - 1))) { // if array at last index is the same as the last... + // element in the list + result.add(array[array.length - 1]); // add to our result list the last element } - return result.toArray(new String[0]); + return result.toArray(new String[0]); // https://www.javatpoint.com/java-list-toarray-method } @@ -199,11 +247,14 @@ public static String[] removeConsecutiveDuplicates(String[] array) { * @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings */ // TODO public static String[] packConsecutiveDuplicates(String[] array) { + + + // string to hold the position at 1 String duplicates = array[0]; for (int i = 1; i < array.length; i++) { - // if we are going through the array and we encounter a lettter thats is same to letter before + // if we are going through the array and we encounter a letter that is the same to letter before if (array[i].equals(array[i - 1])) { duplicates = duplicates + array[i]; } else { @@ -212,6 +263,16 @@ public static String[] packConsecutiveDuplicates(String[] array) { System.out.println("duplicate " + duplicates); } return duplicates.split(" "); + + + + // made a String placeholder + // loop through array + // if array[i] equals array[i-1] + // append array[i] to duplicates placeholder String + // otherwise if not equal add to duplicates String but with a space between + // so all duplicates will be listed 'aaa' or 'bb' with no spaces + // take duplicates String and .split on those spaces to create an array } From 281c71eb3e5e979c0d9e7cbbfad72cefc413dc30 Mon Sep 17 00:00:00 2001 From: Ellis John Date: Tue, 7 Dec 2021 08:04:25 -0500 Subject: [PATCH 5/5] notes --- .../zipcodewilmington/StringArrayUtils.java | 55 ++++++++----------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/StringArrayUtils.java b/src/main/java/com/zipcodewilmington/StringArrayUtils.java index ad0acdb..dd62495 100644 --- a/src/main/java/com/zipcodewilmington/StringArrayUtils.java +++ b/src/main/java/com/zipcodewilmington/StringArrayUtils.java @@ -72,15 +72,6 @@ public static boolean contains(String[] array, String value) { return contains; - - - - - - - - - //// int count = 0; // this counter IS NOT necessary. needs to return boolean value, not a count of something // // // go through each word in array @@ -123,9 +114,9 @@ public static String[] reverse(String[] array) { */ // TODO public static boolean isPalindromic(String[] array) { String[] reversed = reverse(array); // just using above method to reverse String[] array - // creates a new reversed array + // creates a new reversed array if (Arrays.equals(reversed, array)) { // arrays.equals is an array util to compare arrays (pass in arrays) - // if statement comparing both arrays using Arrays.equals + // if statement comparing both arrays using Arrays.equals return true; // return true if theyre equal } return false; // return false if not true. @@ -140,10 +131,10 @@ public static boolean isPangramic(String[] array) { // needs to return a boolean T/F statement String newString = Arrays.toString(array); // converted array to string - // Arrays.toString util to make array into string + // Arrays.toString util to make array into string if (newString.length() < 26) { // if this string is less than 26, has to be false - // this is the obvious, if its less than 26 letters, its clearly false + // this is the obvious, if its less than 26 letters, its clearly false return false; // sometimes its best to knock out the obvious things first } // this is placed above the loop, not a part of the below operation @@ -152,8 +143,8 @@ public static boolean isPangramic(String[] array) { for (int i = 0; i < array.length; i++) { // for loop to iterate through array if (!newString.contains(alphabet[i])) { // if newString DOES NOT contain alphabet at element i - // this is basically the opposite if if it contains the letter return true - // doing it this way continues to rule out more cases + // this is basically the opposite if if it contains the letter return true + // doing it this way continues to rule out more cases return false; // return false } } @@ -210,8 +201,8 @@ public static String[] removeValue(String[] array, String valueToRemove) { /// } return stringList.toArray(new String[0]); // return our stringList, (new String[0]) is signifying... - // that it will be a String array - // we want to return a String[] + // that it will be a String array + // we want to return a String[] } @@ -221,20 +212,23 @@ public static String[] removeValue(String[] array, String valueToRemove) { /// * @return array of Strings with consecutive duplicates removes */ // TODO public static String[] removeConsecutiveDuplicates(String[] array) { - List result = new ArrayList(); // created new list named result -- its always... - // easier to use a list + List result = new ArrayList(); + // created new list named result -- it is always + // easier to use a list for (int i = 0; i < array.length - 1; i++) { // for loop set up if (!array[i].equals(array[i + 1])) { // if theyre do not equal, throw that element into... - // our result list that we created + // our result list that we created result.add(array[i]); // list.add(value); is the general syntax to add value to list } } - // https://www.geeksforgeeks.org/list-get-method-in-java-with-examples/ - // this link is for the .get method seen below + // https://www.geeksforgeeks.org/list-get-method-in-java-with-examples/ + // this link is for the .get method seen below + // THIS BELOW CODE IS FOR CHECKING JUST THE LAST ELEMENT + // THIS IS FOR AN EDGE CASE if (!array[array.length - 1].equals(result.get(result.size() - 1))) { // if array at last index is the same as the last... - // element in the list + // element in the list result.add(array[array.length - 1]); // add to our result list the last element } return result.toArray(new String[0]); // https://www.javatpoint.com/java-list-toarray-method @@ -265,14 +259,13 @@ public static String[] packConsecutiveDuplicates(String[] array) { return duplicates.split(" "); - - // made a String placeholder - // loop through array - // if array[i] equals array[i-1] - // append array[i] to duplicates placeholder String - // otherwise if not equal add to duplicates String but with a space between - // so all duplicates will be listed 'aaa' or 'bb' with no spaces - // take duplicates String and .split on those spaces to create an array +// made a String placeholder +// loop through array +// if array[i] equals array[i-1] +// append array[i] to duplicates placeholder String +// otherwise if not equal add to duplicates String but with a space between +// so all duplicates will be listed 'aaa' or 'bb' with no spaces +// take duplicates String and .split on those spaces to create an array }