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