StringUtils 메소드의 작동 객체는 java.lang.string 유형의 객체이며 JDK가 제공하는 문자열 유형 작동 메소드로 보충되고 안전합니다 (즉, 입력 매개 변수가 NULL이면 그렇지 않습니다. nullpointeerexcetion을 버리지 만 대신 입력이 null이면 소스 코드를 구체적으로 볼 수 있습니다.
생성자 외에도 StringUtils에는 130 개가 넘는 방법이 있으며 모두 정적이므로 StringUtils.xxx ()를 호출 할 수 있습니다.
아래에 일반적으로 사용되는 몇 가지 방법을 간략하게 소개하겠습니다.
StringUtils 클래스는 org.apache.commons.lang.stringutils 아래에 랩핑됩니다
String isempty (String str) 및 Isontempty (String Str)
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtils.isempty (null));
System.out.println (StringUtils.isempty ( ""); // true
System.out.println (StringUtils.isempty ( ""); // false 참고 : 여기에 isempty는 공간 처리를 수행하지 않습니다.
System.out.println (StringUtills.isempty ( " /t /n /f /r"); // false
System.out.println (StringUtils.isempty ( " /b"); // false
System.out.println (StringUtils.isempty ( "Xapido"); // false
System.out.println (StringUtils.isempty ( "x"); // false
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtils.isnotempty (null));
System.out.println (StringUtils.isnotempty ( ""); // false
System.out.println (StringUtils.isnotempty ( ""); // True Note : 여기서는 공간 처리를하지 않았습니다.
System.out.println (StringUtills.isnotempty ( " /t /n /f /r"); // true
System.out.println (StringUtils.isnotempty ( " /b"); // true
System.out.println (StringUtils.isnotempty ( "xapido"); // true
System.out.println (StringUtils.isnotempty ( "x"); // true
String isblank (String Str) 및 Isnotblank (String Str)
다음과 같이 스페이스 복제 코드 코드 포함 :
System.out.println (StringUtills.isblank (null));
System.out.println (StringUtills.isblank ( ""); // true
System.out.println (StringUtills.isblank ( ""); // true
System.out.println (StringUtills.isblank ( " /t /n /f /r"); // true
System.out.println (StringUtils.isblank ( " /b"); // false
System.out.println (StringUtils.isblank ( "xapido"); // false
System.out.println (StringUtills.isblank ( "x"); // false
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtils.isnotblank (null));
System.out.println (StringUtils.isnotblank ( ""); // false
System.out.println (StringUtils.isnotblank ( ""); // false
System.out.println (StringUtills.isnotblank ( " /t /n /f /r"); // false
System.out.println (StringUtills.isnotblank ( " /b"); // true
System.out.println (StringUtils.isnotblank ( "xapido"); // true
System.out.println (StringUtils.isnotblank ( "x"); // true
String Trim (String Str) 및 Trimtonull (String Str) 및 TrimtoEmpty (String Str)
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtil.trim (null));
System.out.println (StringUtills.trim ( ""); // "" ""
System.out.println (StringUtills.trim ( ""); // "" ""
System.out.println (StringUtils.trim ( " /t /n /f /r"); // ""
System.out.println (StringUtil.trim ( " /b"); // ""
System.out.println (StringUtils.trim ( "Xapido"); // "Xapido"
System.out.println (StringUtil.trim ( "x"); // "x"
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtil.trimtonton (null));
System.out.println (StringUtills.trimtontonull ( ""); // null
System.out.println (StringUtills.trimtontonull ( ""); // null
System.out.println (StringUtills.trimtonull ( " /t /n /f /r"); // null
System.out.println (StringUtils.trimtonull ( " /b"); // null
System.out.println (StringUtils.trimtonull ( "Xapido"); // "Xapido"
System.out.println (StringUtils.trimtonull ( "x"); // "x"
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtills.trimtoEmpty (null));
System.out.println (StringUtil.trimtoEmpty ( ""); // ""
System.out.println (StringUtil.trimtoEmpty ( ""); // ""
System.out.println (StringUtils.trimtoEmpty ( " /t /n /f /r"); // ""
System.out.println (StringUtills.trimtoEmpty ( " /b"); // "" ""
System.out.println (StringUtills.trimtoEmpty ( " /bsss"); // sss
System.out.println (StringUtils.trimtoEmpty ( "Xapido"); // "xprapido"
System.out.println (StringUtils.trimtoEmpty ( "x"); // "x"
String Strip (String Str) 및 Striptonull (String Str) 및 StriptoEmpty (String Str)
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtils.strip (null));
System.out.println (StringUtils.strip ( ""); // "" "
System.out.println (StringUtils.strip ( ""); // "" "
System.out.println (StringUtils.strip ( " /t /n /f /r"); // ""
System.out.println (StringUtils.strip ( " /b"); // ""
System.out.println (StringUtils.strip ( " /bsss"); // sss
System.out.println (StringUtils.strip ( "Xapido"); // "Xapido"
System.out.println (StringUtils.strip ( "x"); // "x"
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtills.striptonull (null));
System.out.println (StringUtils.striptonull ( ""); // null
System.out.println (StringUtils.striptonull ( ""); // null
System.out.println (StringUtills.striptonull ( " /t /n /f /r"); // null
System.out.println (StringUtils.striptonull ( " /b"); // ""
System.out.println (StringUtills.striptonull ( " /bsss"); // sss
System.out.println (StringUtils.striptonull ( "Xapido"); // "Xapido"
System.out.println (StringUtils.striptonull ( "x"); // "x"
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtills.striptoEmpty (null));
System.out.println (StringUtils.striptoEmpty ( ""); // ""
System.out.println (StringUtils.striptoEmpty ( ""); // ""
System.out.println (StringUtils.striptoEmpty ( " /t /n /f /r"); // ""
System.out.println (StringUtills.striptoEmpty ( " /b"); // "" ""
System.out.println (StringUtills.striptoEmpty ( " /bsss"); // sss
System.out.println (StringUtils.striptoEmpty ( "Xapido"); // "Xapido"
System.out.println (StringUtils.striptoEmpty ( "x"); // "x"
문자열 스트립 (String Str, String Stripchars)
STR의 양쪽 끝에서 Stripchars의 문자를 제거하십시오. str이 ""와 같으면 stripchams가 null이 있거나 Return Strip (String str)입니다.
String StripStart (String Str, String Stripchars)
11과 마찬가지로 Stripchars의 Stripchars 프론트 엔드에서 캐릭터를 제거하십시오.
String Stripnd (String Str, String Stripchars)
11과 마찬가지로 STR의 끝에 Stripchars의 문자를 제거하십시오.
String [] stripall (String [] strs)
문자열 배열의 각 문자열에서 스트립 (String str)을 다음, 그런 다음 리턴합니다. strs가 null 또는 strs 길이가 0이면 strs 자체입니다.
String [] stripall (String [] strs, String Stripchars)
문자열 배열의 각 문자열의 스트립 (String Stri, String Stripchars)을 한 다음 리턴합니다. strs가 null이거나 strs 길이가 0이면 strs 자체
부울 평등 (String str1, String str2)
두 문자열이 동일했는지 여부를 비교하십시오. 둘 다 비어 있으면 동일하게 간주됩니다.
부울 equalsignorecase (String str1, String str2)
두 문자열이 동일했는지 여부를 비교하면 두 사람이 비어 있으면 동일하게 간주됩니다.
int indexof (String Str, char searchchar)
문자 str에 처음 나타난 캐릭터 Searchchar를 반환합니다. SPEEPCHAR가 STR에 나타나지 않으면 -1이 null이 있거나 ""이면 -1로 돌아갑니다.
int indexof (String Str, char searchchar, int startpos)
문자열 str에서 처음으로 startpos에서 SearchChar가 시작하는 문자 Searchchar를 반환합니다. startpos에서 str에 나타나지 않으면 -1이 null이되면 -1로 돌아갑니다.
int indexof (String str, String searchstr)
문자열 str에서 처음으로 string searchstr를 반환하십시오. STR이 NULL이거나 SearchStr가 NULL 인 경우 SPOUGRSTST가 ""이고 STR이 NULL이 아닌 경우 반환됩니다. STUPINGSTRS가 STR에 있지 않으면 -1이 -1로 반환됩니다.
int ordinalindexof (String str, String searchstr, int orderal)
문자열 str에서 searchstr의 위치를 반환하고, 두 번째 장소의 위치는 문자열 str에 나타납니다. str = null 또는 searchstr = null 또는 Oredinal <= 0 인 경우 -1을 반환합니다.
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtils.ordinalIndexof (NULL, "A", 1);
System.out.println (StringUtils.ordinalIndexof ( "A", NULL, 1);
System.out.println (StringUtills.ordinalIndexof ( "", "", ", 1); // 0
System.out.println (StringUtills.ordinalIndexof ( "aabaabaa", "a", 1); // 0
System.out.println (StringUtils.ordinalIndexof ( "aabaabaa", "a", 2); // 1
System.out.println (StringUtils.ordinalIndexof ( "aabaabaa", "b", 1); // 2
System.out.println (StringUtills.ordinalIndexof ( "aabaabaa", "b", 2); // 5
System.out.println (StringUtils.ordinalIndexof ( "aabaabaa", "ab", 1); // 1
System.out.println (StringUtils.ordinalIndexof ( "aabaabaa", "ab", 2); // 4
System.out.println (StringUtils.ordinalIndexof ( "Aabaabaa", "BC", 1); // -1
System.out.println (StringUtils.ordinalIndexof ( "aabaabaa", "", 1); // 0
System.out.println (StringUtills.ordinalIndexof ( "aabaabaa", "", 2); // 0
int indexof (String str, String searchstr, int startpos)
문자열 str에서 startpos에서 startpos에서 start start start string string str에서 시작합니다.
다음과 같이 코드 코드를 복사하십시오.
System.out.println (StringUtills.indexof (null, "a", 1);
System.out.println (StringUtills.indexof ( "A", NULL, 1);
System.out.println (StringUtils.indexof ( "", "", 1); // 0
System.out.println (StringUtills.indexof ( "Aabaabaa", "A");
System.out.println (StringUtills.indexof ( "Aabaabaa", "A", 2); // 3
System.out.println (StringUtills.indexof ( "Aabaabaa", "B", 1); // 2
System.out.println (StringUtills.indexof ( "Aabaabaa", "B");
System.out.println (StringUtills.indexof ( "Aabaabaa", "ab", 1); // 4
System.out.println (StringUtills.indexof ( "Aabaabaa", "ab", 2);
System.out.println (StringUtils.indexof ( "aabaabaa", "bc", 1); // -1
System.out.println (StringUtills.indexof ( "Aabaabaa", ", 1); // 1
System.out.println (StringUtills.indexof ( "Aabaabaa", "", 2); // 2
int lastindexof (String Str, char searchchar)
기본 원칙은 int indexof (String Str, char searchchar)와 동일합니다.
int lastindexof (String Str, char searchchar, int startpos)
기본 원칙은 Int Indexo (String Str, Char Searchchar, Int Startpos)와 동일합니다.
int lastIndexof (String str, String searchstr)
기본 원칙은 int indexf (String str, String searchstr)와 동일합니다.
int lastIndexof (String str, String searchstr, int startpos)
기본 원칙은 int indexof (String str, String searchstr, int startpos)와 동일합니다.