StringArrayUtils.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import java.util.List;
  2. import java.util.Arrays;
  3. /**
  4. * Created by leon on 1/29/18.
  5. */
  6. public class StringArrayUtils {
  7. /**
  8. * @param array array of String objects
  9. * @return first element of specified array
  10. */ // TODO
  11. public static String getFirstElement(String[] array) {
  12. List<String> random = Arrays.asList("the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog");
  13. String first = random.get(0);
  14. return first;
  15. }
  16. /**
  17. * @param array array of String objects
  18. * @return second element in specified array
  19. */
  20. public static String getSecondElement(String[] array) {
  21. List <String> random = Arrays.asList("the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog");
  22. String second = random.get(1);
  23. return second;
  24. }
  25. /**
  26. * @param array array of String objects
  27. * @return last element in specified array
  28. */ // TODO
  29. public static String getLastElement(String[] array) {
  30. List <String> random = Arrays.asList("the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog");
  31. String last = random.get(array.length-1);
  32. return last;
  33. }
  34. /**
  35. * @param array array of String objects
  36. * @return second to last element in specified array
  37. */ // TODO
  38. public static String getSecondToLastElement(String[] array) {
  39. List <String> random = Arrays.asList("the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog");
  40. String secondToLast = random.get(array.length-2);
  41. return secondToLast;
  42. }
  43. /**
  44. * @param array array of String objects
  45. * @param value value to check array for
  46. * @return true if the array contains the specified `value`
  47. */ // TODO
  48. public static boolean contains(String[] array, String value) {
  49. String[] arr = {"the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"};
  50. if (Arrays.asList(arr).contains("quick") == true){
  51. return true;
  52. }
  53. else{
  54. }
  55. return false ;
  56. }
  57. /**
  58. * @param array of String objects
  59. * @return an array with identical contents in reverse order
  60. */ // TODO
  61. public static String[] reverse(String[] array) {
  62. return null;
  63. }
  64. /**
  65. * @param array array of String objects
  66. * @return true if the order of the array is the same backwards and forwards
  67. */ // TODO
  68. public static boolean isPalindromic(String[] array) {
  69. return false;
  70. }
  71. /**
  72. * @param array array of String objects
  73. * @return true if each letter in the alphabet has been used in the array
  74. */ // TODO
  75. public static boolean isPangramic(String[] array) {
  76. return false;
  77. }
  78. /**
  79. * @param array array of String objects
  80. * @param value value to check array for
  81. * @return number of occurrences the specified `value` has occurred
  82. */ // TODO
  83. public static int getNumberOfOccurrences(String[] array, String value) {
  84. return 0;
  85. }
  86. /**
  87. * @param array array of String objects
  88. * @param valueToRemove value to remove from array
  89. * @return array with identical contents excluding values of `value`
  90. */ // TODO
  91. public static String[] removeValue(String[] array, String valueToRemove) {
  92. return null;
  93. }
  94. /**
  95. * @param array array of chars
  96. * @return array of Strings with consecutive duplicates removes
  97. */ // TODO
  98. public static String[] removeConsecutiveDuplicates(String[] array) {
  99. return null;
  100. }
  101. /**
  102. * @param array array of chars
  103. * @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings
  104. */ // TODO
  105. public static String[] packConsecutiveDuplicates(String[] array) {
  106. return null;
  107. }
  108. }