123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * jaejoson on 10/18/18
  3. */
  4. public class StringUtilities {
  5. /**
  6. * @return `Hello World` as a string
  7. */
  8. public static String getHelloWorld() {
  9. String getHelloWorld = "Hello World";
  10. return getHelloWorld;
  11. }
  12. /**
  13. * @param firstSegment a string to be added to
  14. * @param secondSegment a string to add
  15. * @return the concatenation of two strings, `firstSegment`, and `secondSegment`
  16. */
  17. public static String concatenation(String firstSegment, String secondSegment){
  18. String combo = firstSegment + secondSegment;
  19. return combo;
  20. }
  21. /**
  22. * @param firstSegment a string to be added to
  23. * @param secondSegment a string to add
  24. * @return the concatenation of an integer, `firstSegment`, and a String, `secondSegment`
  25. */
  26. public static String concatenation(int firstSegment, String secondSegment){
  27. String combo = firstSegment + secondSegment;
  28. return combo;
  29. }
  30. /**
  31. * @param input a string to be manipulated
  32. * @return the first 3 characters of `input`
  33. */
  34. public static String getPrefix(String input){
  35. String mani = input.substring(0, 3);
  36. return mani;
  37. }
  38. /**
  39. * @param input a string to be manipulated
  40. * @return the last 3 characters of `input`
  41. */
  42. public static String getSuffix(String input){
  43. String mani = input.substring((input.length()-3), input.length());
  44. return mani;
  45. }
  46. /**
  47. * @param inputValue the value to be compared
  48. * @param comparableValue the value to be compared against
  49. * @return the equivalence of two strings, `inputValue` and `comparableValue`
  50. */
  51. public static Boolean compareTwoStrings(String inputValue, String comparableValue){
  52. Boolean compar = inputValue.equals(comparableValue);
  53. return compar;
  54. }
  55. /**
  56. * @param inputValue the value input from user
  57. * @return the middle character of `inputValue`
  58. */
  59. public static Character getMiddleCharacter(String inputValue){
  60. int theMiddleOne;
  61. if ((inputValue.length()/2)% 2 == 0) {
  62. theMiddleOne = ((inputValue.length()/2) - 1);
  63. } else {
  64. theMiddleOne = (inputValue.length()/2);
  65. }
  66. return inputValue.charAt(theMiddleOne);
  67. }
  68. /**
  69. * @param spaceDelimitedString a string, representative of a sentence, containing spaces
  70. * @return the first sequence of characters
  71. */
  72. public static String getFirstWord(String spaceDelimitedString){
  73. String fir[] = spaceDelimitedString.split(" ");
  74. return fir[0];
  75. /*int index = spaceDelimitedString.indexOf(' ');
  76. if (index > -1) {
  77. return spaceDelimitedString.substring(0, index);
  78. } else {
  79. return spaceDelimitedString;
  80. }
  81. */
  82. }
  83. /**
  84. * @param spaceDelimitedString a string delimited by spaces
  85. * @return the second word of a string delimited by spaces.
  86. */
  87. public static String getSecondWord(String spaceDelimitedString){
  88. String sec[] = spaceDelimitedString.split(" ");
  89. return sec[1];
  90. }
  91. /**
  92. * @param stringToReverse
  93. * @return an identical string with characters in reverse order.
  94. */
  95. public static String reverse(String stringToReverse) {
  96. StringBuilder newRev = new StringBuilder(stringToReverse);
  97. return newRev.reverse().toString();
  98. }
  99. }