StringArrayUtils.java 3.1KB

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