Lines Matching refs:string

35    * Returns the given string if it is non-null; the empty string otherwise.
37 * @param string the string to test and possibly return
38 * @return {@code string} itself if it is non-null; {@code ""} if it is null
40 public static String nullToEmpty(String string) {
41 return (string == null) ? "" : string;
45 * Returns the given string if it is nonempty; {@code null} otherwise.
47 * @param string the string to test and possibly return
48 * @return {@code string} itself if it is nonempty; {@code null} if it is
51 public static String emptyToNull(String string) {
52 return isNullOrEmpty(string) ? null : string;
56 * Returns {@code true} if the given string is null or is the empty string.
58 * <p>Consider normalizing your string references with {@link #nullToEmpty}.
65 * @param string a string reference to check
66 * @return {@code true} if the string is null or is the empty string
68 public static boolean isNullOrEmpty(String string) {
69 return string == null || string.length() == 0; // string.isEmpty() in Java 6
73 * Returns a string, of length at least {@code minLength}, consisting of
74 * {@code string} prepended with as many copies of {@code padChar} as are
84 * @param string the string which should appear at the end of the result
85 * @param minLength the minimum length the resulting string must have. Can be
86 * zero or negative, in which case the input string is always returned.
89 * @return the padded string
91 public static String padStart(String string, int minLength, char padChar) {
92 checkNotNull(string); // eager for GWT.
93 if (string.length() >= minLength) {
94 return string;
97 for (int i = string.length(); i < minLength; i++) {
100 sb.append(string);
105 * Returns a string, of length at least {@code minLength}, consisting of
106 * {@code string} appended with as many copies of {@code padChar} as are
116 * @param string the string which should appear at the beginning of the result
117 * @param minLength the minimum length the resulting string must have. Can be
118 * zero or negative, in which case the input string is always returned.
121 * @return the padded string
123 public static String padEnd(String string, int minLength, char padChar) {
124 checkNotNull(string); // eager for GWT.
125 if (string.length() >= minLength) {
126 return string;
129 sb.append(string);
130 for (int i = string.length(); i < minLength; i++) {
137 * Returns a string consisting of a specific number of concatenated copies of
138 * an input string. For example, {@code repeat("hey", 3)} returns the string
141 * @param string any non-null string
143 * @return a string containing {@code string} repeated {@code count} times
144 * (the empty string if {@code count} is zero)
147 public static String repeat(String string, int count) {
148 checkNotNull(string); // eager for GWT.
153 StringBuilder builder = new StringBuilder(string.length() * count);
155 builder.append(string);