cn.hutool.core.util.StrUtil.equals()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(868)

本文整理了Java中cn.hutool.core.util.StrUtil.equals()方法的一些代码示例,展示了StrUtil.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StrUtil.equals()方法的具体详情如下:
包路径:cn.hutool.core.util.StrUtil
类名称:StrUtil
方法名:equals

StrUtil.equals介绍

[英]比较两个字符串(大小写敏感)。

equals(null, null)   = true 
equals(null, "abc")  = false 
equals("abc", null)  = false 
equals("abc", "abc") = true 
equals("abc", "ABC") = false

[中]比较两个字符串(大小写敏感)。

equals(null, null)   = true 
equals(null, "abc")  = false 
equals("abc", null)  = false 
equals("abc", "abc") = true 
equals("abc", "ABC") = false

代码示例

代码示例来源:origin: looly/hutool

/**
 * 比较两个字符串(大小写敏感)。
 * 
 * <pre>
 * equals(null, null)   = true
 * equals(null, &quot;abc&quot;)  = false
 * equals(&quot;abc&quot;, null)  = false
 * equals(&quot;abc&quot;, &quot;abc&quot;) = true
 * equals(&quot;abc&quot;, &quot;ABC&quot;) = false
 * </pre>
 * 
 * @param str1 要比较的字符串1
 * @param str2 要比较的字符串2
 * 
 * @return 如果两个字符串相同,或者都是<code>null</code>,则返回<code>true</code>
 */
public static boolean equals(CharSequence str1, CharSequence str2) {
  return equals(str1, str2, false);
}

代码示例来源:origin: looly/hutool

if (StrUtil.equals(file1.getCanonicalPath(), file2.getCanonicalPath())) {
  return true;
if (StrUtil.equals(file1.getAbsolutePath(), file2.getAbsolutePath())) {
  return true;

代码示例来源:origin: looly/hutool

/**
 * 比较两个字符串(大小写敏感)。
 * 
 * <pre>
 * equals(null, null)   = true
 * equals(null, &quot;abc&quot;)  = false
 * equals(&quot;abc&quot;, null)  = false
 * equals(&quot;abc&quot;, &quot;abc&quot;) = true
 * equals(&quot;abc&quot;, &quot;ABC&quot;) = false
 * </pre>
 * 
 * @param str1 要比较的字符串1
 * @param str2 要比较的字符串2
 * 
 * @return 如果两个字符串相同,或者都是<code>null</code>,则返回<code>true</code>
 */
public static boolean equals(CharSequence str1, CharSequence str2) {
  return equals(str1, str2, false);
}

代码示例来源:origin: looly/hutool

if (StrUtil.equals(file1.getCanonicalPath(), file2.getCanonicalPath())) {
  return true;
if (StrUtil.equals(file1.getAbsolutePath(), file2.getAbsolutePath())) {
  return true;

代码示例来源:origin: looly/hutool

/**
 * 比较两个字符串(大小写不敏感)。
 * 
 * <pre>
 * equalsIgnoreCase(null, null)   = true
 * equalsIgnoreCase(null, &quot;abc&quot;)  = false
 * equalsIgnoreCase(&quot;abc&quot;, null)  = false
 * equalsIgnoreCase(&quot;abc&quot;, &quot;abc&quot;) = true
 * equalsIgnoreCase(&quot;abc&quot;, &quot;ABC&quot;) = true
 * </pre>
 * 
 * @param str1 要比较的字符串1
 * @param str2 要比较的字符串2
 * 
 * @return 如果两个字符串相同,或者都是<code>null</code>,则返回<code>true</code>
 */
public static boolean equalsIgnoreCase(CharSequence str1, CharSequence str2) {
  return equals(str1, str2, true);
}

代码示例来源:origin: looly/hutool

/**
 * 比较两个字符串(大小写不敏感)。
 * 
 * <pre>
 * equalsIgnoreCase(null, null)   = true
 * equalsIgnoreCase(null, &quot;abc&quot;)  = false
 * equalsIgnoreCase(&quot;abc&quot;, null)  = false
 * equalsIgnoreCase(&quot;abc&quot;, &quot;abc&quot;) = true
 * equalsIgnoreCase(&quot;abc&quot;, &quot;ABC&quot;) = true
 * </pre>
 * 
 * @param str1 要比较的字符串1
 * @param str2 要比较的字符串2
 * 
 * @return 如果两个字符串相同,或者都是<code>null</code>,则返回<code>true</code>
 */
public static boolean equalsIgnoreCase(CharSequence str1, CharSequence str2) {
  return equals(str1, str2, true);
}

代码示例来源:origin: looly/hutool

/**
 * 去除两边的指定字符串
 * 
 * @param str 被处理的字符串
 * @param prefixOrSuffix 前缀或后缀
 * @return 处理后的字符串
 * @since 3.1.2
 */
public static String strip(CharSequence str, CharSequence prefixOrSuffix) {
  if (equals(str, prefixOrSuffix)) {
    // 对于去除相同字符的情况单独处理
    return EMPTY;
  }
  return strip(str, prefixOrSuffix, prefixOrSuffix);
}

代码示例来源:origin: looly/hutool

/**
 * 去除两边的指定字符串
 * 
 * @param str 被处理的字符串
 * @param prefixOrSuffix 前缀或后缀
 * @return 处理后的字符串
 * @since 3.1.2
 */
public static String strip(CharSequence str, CharSequence prefixOrSuffix) {
  if (equals(str, prefixOrSuffix)) {
    // 对于去除相同字符的情况单独处理
    return EMPTY;
  }
  return strip(str, prefixOrSuffix, prefixOrSuffix);
}

代码示例来源:origin: looly/hutool

@Override
  public int select(LsEntry entry) {
    String fileName = entry.getFilename();
    if (false == StrUtil.equals(".", fileName) && false == StrUtil.equals("..", fileName)) {
      if (null == filter || filter.accept(entry)) {
        fileNames.add(entry.getFilename());
      }
    }
    return CONTINUE;
  }
});

代码示例来源:origin: looly/hutool

@Override
  public int select(LsEntry entry) {
    String fileName = entry.getFilename();
    if (false == StrUtil.equals(".", fileName) && false == StrUtil.equals("..", fileName)) {
      if (null == filter || filter.accept(entry)) {
        fileNames.add(entry.getFilename());
      }
    }
    return CONTINUE;
  }
});

代码示例来源:origin: looly/hutool

/**
 * 给定字符串是否与提供的中任一字符串相同,相同则返回{@code true},没有相同的返回{@code false}<br>
 * 如果参与比对的字符串列表为空,返回{@code false}
 * 
 * @param str1 给定需要检查的字符串
 * @param ignoreCase 是否忽略大小写
 * @param strs 需要参与比对的字符串列表
 * @return 是否相同
 * @since 4.3.2
 */
public static boolean equalsAny(CharSequence str1, boolean ignoreCase, CharSequence... strs) {
  if (ArrayUtil.isEmpty(strs)) {
    return false;
  }
  for (CharSequence str : strs) {
    if (equals(str1, str, ignoreCase)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: looly/hutool

/**
 * 给定字符串是否与提供的中任一字符串相同,相同则返回{@code true},没有相同的返回{@code false}<br>
 * 如果参与比对的字符串列表为空,返回{@code false}
 * 
 * @param str1 给定需要检查的字符串
 * @param ignoreCase 是否忽略大小写
 * @param strs 需要参与比对的字符串列表
 * @return 是否相同
 * @since 4.3.2
 */
public static boolean equalsAny(CharSequence str1, boolean ignoreCase, CharSequence... strs) {
  if (ArrayUtil.isEmpty(strs)) {
    return false;
  }
  for (CharSequence str : strs) {
    if (equals(str1, str, ignoreCase)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: looly/hutool

/**
 * 按照方法名查找指定方法名的方法,只返回匹配到的第一个方法,如果找不到对应的方法则返回<code>null</code>
 * 
 * <p>
 * 此方法只检查方法名是否一致,并不检查参数的一致性。
 * </p>
 * 
 * @param clazz 类,如果为{@code null}返回{@code null}
 * @param ignoreCase 是否忽略大小写
 * @param methodName 方法名,如果为空字符串返回{@code null}
 * @return 方法
 * @throws SecurityException 无权访问抛出异常
 * @since 4.3.2
 */
public static Method getMethodByName(Class<?> clazz, boolean ignoreCase, String methodName) throws SecurityException {
  if (null == clazz || StrUtil.isBlank(methodName)) {
    return null;
  }
  final Method[] methods = getMethods(clazz);
  if (ArrayUtil.isNotEmpty(methods)) {
    for (Method method : methods) {
      if (StrUtil.equals(methodName, method.getName(), ignoreCase)) {
        return method;
      }
    }
  }
  return null;
}

代码示例来源:origin: looly/hutool

/**
 * 按照方法名查找指定方法名的方法,只返回匹配到的第一个方法,如果找不到对应的方法则返回<code>null</code>
 * 
 * <p>
 * 此方法只检查方法名是否一致,并不检查参数的一致性。
 * </p>
 * 
 * @param clazz 类,如果为{@code null}返回{@code null}
 * @param ignoreCase 是否忽略大小写
 * @param methodName 方法名,如果为空字符串返回{@code null}
 * @return 方法
 * @throws SecurityException 无权访问抛出异常
 * @since 4.3.2
 */
public static Method getMethodByName(Class<?> clazz, boolean ignoreCase, String methodName) throws SecurityException {
  if (null == clazz || StrUtil.isBlank(methodName)) {
    return null;
  }
  final Method[] methods = getMethods(clazz);
  if (ArrayUtil.isNotEmpty(methods)) {
    for (Method method : methods) {
      if (StrUtil.equals(methodName, method.getName(), ignoreCase)) {
        return method;
      }
    }
  }
  return null;
}

代码示例来源:origin: looly/hutool

if (ArrayUtil.isNotEmpty(methods)) {
  for (Method method : methods) {
    if (StrUtil.equals(methodName, method.getName(), ignoreCase)) {
      if (ClassUtil.isAllAssignableFrom(method.getParameterTypes(), paramTypes)) {
        return method;

代码示例来源:origin: looly/hutool

if (ArrayUtil.isNotEmpty(methods)) {
  for (Method method : methods) {
    if (StrUtil.equals(methodName, method.getName(), ignoreCase)) {
      if (ClassUtil.isAllAssignableFrom(method.getParameterTypes(), paramTypes)) {
        return method;

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 比较两个字符串(大小写不敏感)。
 * 
 * <pre>
 * equalsIgnoreCase(null, null)   = true
 * equalsIgnoreCase(null, &quot;abc&quot;)  = false
 * equalsIgnoreCase(&quot;abc&quot;, null)  = false
 * equalsIgnoreCase(&quot;abc&quot;, &quot;abc&quot;) = true
 * equalsIgnoreCase(&quot;abc&quot;, &quot;ABC&quot;) = true
 * </pre>
 * 
 * @param str1 要比较的字符串1
 * @param str2 要比较的字符串2
 * 
 * @return 如果两个字符串相同,或者都是<code>null</code>,则返回<code>true</code>
 */
public static boolean equalsIgnoreCase(CharSequence str1, CharSequence str2) {
  return equals(str1, str2, true);
}

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 去除两边的指定字符串
 * 
 * @param str 被处理的字符串
 * @param prefixOrSuffix 前缀或后缀
 * @return 处理后的字符串
 * @since 3.1.2
 */
public static String strip(CharSequence str, CharSequence prefixOrSuffix) {
  if (equals(str, prefixOrSuffix)) {
    // 对于去除相同字符的情况单独处理
    return EMPTY;
  }
  return strip(str, prefixOrSuffix, prefixOrSuffix);
}

代码示例来源:origin: cn.hutool/hutool-all

@Override
  public int select(LsEntry entry) {
    String fileName = entry.getFilename();
    if (false == StrUtil.equals(".", fileName) && false == StrUtil.equals("..", fileName)) {
      if (null == filter || filter.accept(entry)) {
        fileNames.add(entry.getFilename());
      }
    }
    return CONTINUE;
  }
});

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 给定字符串是否与提供的中任一字符串相同,相同则返回{@code true},没有相同的返回{@code false}<br>
 * 如果参与比对的字符串列表为空,返回{@code false}
 * 
 * @param str1 给定需要检查的字符串
 * @param ignoreCase 是否忽略大小写
 * @param strs 需要参与比对的字符串列表
 * @return 是否相同
 * @since 4.3.2
 */
public static boolean equalsAny(CharSequence str1, boolean ignoreCase, CharSequence... strs) {
  if (ArrayUtil.isEmpty(strs)) {
    return false;
  }
  for (CharSequence str : strs) {
    if (equals(str1, str, ignoreCase)) {
      return true;
    }
  }
  return false;
}

相关文章

微信公众号

最新文章

更多

StrUtil类方法