本文整理了Java中java.lang.String.isEmpty()
方法的一些代码示例,展示了String.isEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。String.isEmpty()
方法的具体详情如下:
包路径:java.lang.String
类名称:String
方法名:isEmpty
[英]Returns true if, and only if, #length() is 0.
[中]当且仅当#length()为0时返回true。
代码示例来源:origin: spring-projects/spring-framework
public PatternVirtualFileVisitor(String rootPath, String subPattern, PathMatcher pathMatcher) {
this.subPattern = subPattern;
this.pathMatcher = pathMatcher;
this.rootPath = (rootPath.isEmpty() || rootPath.endsWith("/") ? rootPath : rootPath + "/");
}
代码示例来源:origin: stackoverflow.com
public static boolean empty( final String s ) {
// Null-safe, short-circuit evaluation.
return s == null || s.trim().isEmpty();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Check that the given {@code String} is neither {@code null} nor of length 0.
* <p>Note: this method returns {@code true} for a {@code String} that
* purely consists of whitespace.
* @param str the {@code String} to check (may be {@code null})
* @return {@code true} if the {@code String} is not {@code null} and has length
* @see #hasLength(CharSequence)
* @see #hasText(String)
*/
public static boolean hasLength(@Nullable String str) {
return (str != null && !str.isEmpty());
}
代码示例来源:origin: stackoverflow.com
List<String> list = new ArrayList<>();
// This is a clever way to create the iterator and call iterator.hasNext() like
// you would do in a while-loop. It would be the same as doing:
// Iterator<String> iterator = list.iterator();
// while (iterator.hasNext()) {
for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
String string = iterator.next();
if (string.isEmpty()) {
// Remove the current element from the iterator and the list.
iterator.remove();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public T convert(String source) {
if (source.isEmpty()) {
// It's an empty enum identifier: reset the enum value to null.
return null;
}
return (T) Enum.valueOf(this.enumType, source.trim());
}
}
代码示例来源:origin: spring-projects/spring-framework
protected boolean isNamespaceDeclaration(QName qName) {
String prefix = qName.getPrefix();
String localPart = qName.getLocalPart();
return (XMLConstants.XMLNS_ATTRIBUTE.equals(localPart) && prefix.isEmpty()) ||
(XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) && !localPart.isEmpty());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Character convert(String source) {
if (source.isEmpty()) {
return null;
}
if (source.length() > 1) {
throw new IllegalArgumentException(
"Can only convert a [String] with length of 1 to a [Character]; string value '" + source + "' has length of " + source.length());
}
return source.charAt(0);
}
代码示例来源:origin: square/okhttp
static void checkName(String name) {
if (name == null) throw new NullPointerException("name == null");
if (name.isEmpty()) throw new IllegalArgumentException("name is empty");
for (int i = 0, length = name.length(); i < length; i++) {
char c = name.charAt(i);
if (c <= '\u0020' || c >= '\u007f') {
throw new IllegalArgumentException(Util.format(
"Unexpected char %#04x at %d in header name: %s", (int) c, i, name));
}
}
}
代码示例来源:origin: google/guava
@Override
public void parse(CacheBuilderSpec spec, String key, String value) {
checkArgument(value != null && !value.isEmpty(), "value of key %s omitted", key);
try {
parseInteger(spec, Integer.parseInt(value));
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
format("key %s value set to %s, must be integer", key, value), e);
}
}
}
代码示例来源:origin: google/guava
@Override
protected String computeNext() {
if (lines.hasNext()) {
String next = lines.next();
// skip last line if it's empty
if (lines.hasNext() || !next.isEmpty()) {
return next;
}
}
return endOfData();
}
};
代码示例来源:origin: google/guava
@Override
public void parse(CacheBuilderSpec spec, String key, String value) {
checkArgument(value != null && !value.isEmpty(), "value of key %s omitted", key);
try {
parseLong(spec, Long.parseLong(value));
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
format("key %s value set to %s, must be integer", key, value), e);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
private String resolveExpression(A annotation) {
for (String attributeName : EXPRESSION_ATTRIBUTES) {
Object val = AnnotationUtils.getValue(annotation, attributeName);
if (val instanceof String) {
String str = (String) val;
if (!str.isEmpty()) {
return str;
}
}
}
throw new IllegalStateException("Failed to resolve expression: " + annotation);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public T convert(String source) {
if (source.isEmpty()) {
return null;
}
return NumberUtils.parseNumber(source, this.targetType);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Base64-decode the given byte array from an UTF-8 String.
* @param src the encoded UTF-8 String
* @return the original byte array
*/
public static byte[] decodeFromString(String src) {
if (src.isEmpty()) {
return new byte[0];
}
return decode(src.getBytes(DEFAULT_CHARSET));
}
代码示例来源:origin: square/okhttp
static int readInt(BufferedSource source) throws IOException {
try {
long result = source.readDecimalLong();
String line = source.readUtf8LineStrict();
if (result < 0 || result > Integer.MAX_VALUE || !line.isEmpty()) {
throw new IOException("expected an int but was \"" + result + line + "\"");
}
return (int) result;
} catch (NumberFormatException e) {
throw new IOException(e.getMessage());
}
}
代码示例来源:origin: google/guava
private static String firstCharOnlyToUpper(String word) {
return word.isEmpty()
? word
: Ascii.toUpperCase(word.charAt(0)) + Ascii.toLowerCase(word.substring(1));
}
}
代码示例来源:origin: square/okhttp
/**
* Sets this request's {@code Cache-Control} header, replacing any cache control headers already
* present. If {@code cacheControl} doesn't define any directives, this clears this request's
* cache-control headers.
*/
public Builder cacheControl(CacheControl cacheControl) {
String value = cacheControl.toString();
if (value.isEmpty()) return removeHeader("Cache-Control");
return header("Cache-Control", value);
}
代码示例来源:origin: spring-projects/spring-framework
private String getPartName(MethodParameter methodParam, @Nullable RequestPart requestPart) {
String partName = (requestPart != null ? requestPart.name() : "");
if (partName.isEmpty()) {
partName = methodParam.getParameterName();
if (partName == null) {
throw new IllegalArgumentException("Request part name for argument type [" +
methodParam.getNestedParameterType().getName() +
"] not specified, and parameter name information not found in class file either.");
}
}
return partName;
}
代码示例来源:origin: spring-projects/spring-framework
private String getPartName(MethodParameter methodParam, @Nullable RequestPart requestPart) {
String partName = (requestPart != null ? requestPart.name() : "");
if (partName.isEmpty()) {
partName = methodParam.getParameterName();
if (partName == null) {
throw new IllegalArgumentException("Request part name for argument type [" +
methodParam.getNestedParameterType().getName() +
"] not specified, and parameter name information not found in class file either.");
}
}
return partName;
}
代码示例来源:origin: spring-projects/spring-framework
private Expression parseTemplate(String expressionString, ParserContext context) throws ParseException {
if (expressionString.isEmpty()) {
return new LiteralExpression("");
}
Expression[] expressions = parseExpressions(expressionString, context);
if (expressions.length == 1) {
return expressions[0];
}
else {
return new CompositeStringExpression(expressionString, expressions);
}
}
内容来源于网络,如有侵权,请联系作者删除!