StrUtil.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package com.sooka.common.utils;
  2. import org.apache.commons.lang3.StringUtils;
  3. import java.util.Arrays;
  4. import java.util.HashSet;
  5. import java.util.Set;
  6. import java.util.UUID;
  7. public class StrUtil {
  8. /**
  9. * 判断字符串是否为空
  10. * @param str
  11. * @return
  12. */
  13. public static boolean isBlank(String str) {
  14. return str == null || str.length() <= 0;
  15. }
  16. /**
  17. * 替换中文逗号
  18. * @param content
  19. * @return
  20. */
  21. public static String replace(String content) {
  22. String word = content.replace(",", ",").trim();
  23. return word;
  24. }
  25. /**
  26. * 获取文件扩展名
  27. *
  28. * @param filename
  29. * @return
  30. */
  31. public static String getExtensionName(String filename) {
  32. if ((filename != null) && (filename.length() > 0)) {
  33. int dot = filename.lastIndexOf('.');
  34. if ((dot > -1) && (dot < (filename.length() - 1))) {
  35. return filename.substring(dot + 1);
  36. }
  37. }
  38. return filename;
  39. }
  40. /**
  41. *
  42. * 获取uuid
  43. *
  44. * @return
  45. */
  46. public static String getUUID() {
  47. UUID uuid = UUID.randomUUID();
  48. return uuid.toString().replace("-", "");
  49. }
  50. /* 字符串数组排重 */
  51. public static String[] excludeRepeatStr(String str){
  52. if(StrUtil.isBlank(str)) {
  53. return null;
  54. }
  55. String[] ss = str.replace(" ","").split(",");
  56. Arrays.sort(ss);
  57. Set<String> prodCodeSet = new HashSet<>();
  58. prodCodeSet.addAll(Arrays.asList(ss));
  59. ss = prodCodeSet.toArray(new String[]{});
  60. return ss;
  61. }
  62. public static boolean isNotNumeric(String ...strs) {
  63. for(String str:strs){
  64. if(StringUtils.isNumeric(str)) {
  65. return false;
  66. }
  67. }
  68. return true;
  69. }
  70. public static boolean isContain(String[] strs,String str) {
  71. if(CmsUtil.isNullOrEmpty(strs)) {
  72. return false;
  73. }
  74. for(String s:strs){
  75. if(s.equals(str)) {
  76. return true;
  77. }
  78. }
  79. return false;
  80. }
  81. /*判断一个字符是否是中文*/
  82. public static boolean isChinese(char c) {
  83. return c >= 0x4E00 && c <= 0x9FA5;
  84. }
  85. /*判断一个字符串是否含有中文*/
  86. public static boolean isChinese(String str) {
  87. if (str == null) {
  88. return false;
  89. }
  90. for (char c : str.toCharArray()) {
  91. if (isChinese(c)) {
  92. return true;
  93. }
  94. }
  95. return false;
  96. }
  97. public static void main(String args[]){
  98. // System.out.println( excludeRepeatStr("1,2,1"));
  99. // System.out.println(isNotNumeric("0","46"));
  100. String[] ss = {"1000","200"};
  101. System.out.println(isContain(ss,"200"));
  102. }
  103. }