You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+83-1Lines changed: 83 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -871,6 +871,88 @@ StringBuilder str4 = new StringBuilder(my_str);
871
871
872
872
Note : All the code explanation is available on this [link](https://github.com/ackwolver335/Java-Coder/blob/main/str_build_clss.java).
873
873
874
+
## StringTokenizer Class
875
+
876
+
StringTokenizer class in Java is used to break a string into tokens. A StringTokenizer object internally maintains a current position within the string to be tokenized. Some operations advance this current position past the characters processed.
877
+
878
+
A token is returned by taking a substring of the string that was used to create the StringTokenizer object. It provides the first step in the parsing process often called lexer or scanner.
879
+
880
+
### Constructors in StringTokenizer Class
881
+
882
+
-**StringTokenizer(String str)** : It is used for creating a StringTokenizer Object without passing the delimeter as the default delimeter value which is taken is space here.
883
+
884
+
Syntax Code :
885
+
886
+
```java
887
+
StringTokenizer str1 =newStringTokenizer("This is a general String");
888
+
```
889
+
890
+
-**StringTokenizer(String str,String delimeter)** : It is used to create a StringTokenizer Object together by passing delimeter as per our choice and also that must be present inside the String we have taken.
-**StringTokenizer(String str,String delimeter,boolean flag)** : In this method of creating a StringTokenizer Constructor a last optional argument is passed in order to allow using the String Delimeter and the default value of this delimeter is true.
899
+
900
+
Syntax Code :
901
+
902
+
```java
903
+
StringTokenizer str3 =newStringTokenizer("String : Here !",":",true);
904
+
```
905
+
906
+
### Methods in StringTokenizer Class
907
+
908
+
|**Method Name**|**Uses**|
909
+
| :-------------- | :------- |
910
+
|**countTokens()**| It is used in order to count the number of Tokens in which the String of StringToknizer Class is been divided |
911
+
|**hasMoreTokens()**| This method is used in order to check the presence of Tokens inside the StringTokenizer Object. |
912
+
|**nextToken()**| It is used in order to move onto the next available token in the StringTokenizer's Object. |
913
+
|**hasMoreElements()**| This method works similar to the *hasMoreToken()* just by treating the Tokens as the Elements of the Object. |
914
+
|**nextElement()**| It works similar to the *nextToken()* method just by treating the Tokens as Elements |
915
+
916
+
Note : The Code File and Explanation is available on this [link](https://github.com/ackwolver335/Java-Coder/blob/main/str1_tkn.java)
917
+
918
+
## StringJoiner Class
919
+
920
+
StringJoiner is a class in java.util package is used to construct a sequence of characters(strings) separated by a delimiter and optionally starting with a supplied prefix and ending with a given suffix.
921
+
922
+
Though this can also be done with the help of the StringBuilder class to append delimiter after each string, StringJoiner provides an easy way to do that without much code to write.
923
+
924
+
Note : We also uses a package **java.util.StringJoiner** while working with StringJoiner Class and its Objects.
925
+
926
+
### Constructors in StringJoiner Class
927
+
928
+
-**StringJoiner(CharSequence delimeter)** : This method is used in order to construct the StringJoiner Object without the presence of characters, prefix, suffix and a copy of the supplied delimeter.
929
+
930
+
Syntax Code :
931
+
932
+
```java
933
+
StringJoiner str1 =newStringJoiner(",");
934
+
```
935
+
936
+
-**StringJoiner(CharSequence delimeter,CharSequence prefix,CharSequence suffix)** : This method in order to construct a StringJoiner with no characters using copies of the supplied prefix, delimiter, and suffix. If no characters are added to the StringJoiner and methods accessing the string value are invoked, it will return the prefix + suffix (or properties thereof) in the result unless setEmptyValue has first been called.
937
+
938
+
Syntax Code :
939
+
940
+
```java
941
+
StringJoiner str2 =newStringJoiner(",","Strin Before Delimeter","String after Delimeter");
942
+
```
943
+
944
+
### Methods of StringJoiner Class
945
+
946
+
|**Method's Name**|**Uses**|
947
+
| :---------------- | :------- |
948
+
|**add()**| Used to add CharSequence or String Data to the StringJoiner Class Object's String |
949
+
|**length()**| Used to find the length of the String inside StringJoiner Class's Object or No. of Characters inside the String |
950
+
|**merge()**| This method is used in order to merge two Strings of different StringJoiner Class's Object |
951
+
|**toString()**| It is a simple method used to convert the StringJoiner Object to String Data Type |
952
+
|**setEmptyValue()**| It is used in order to set the value of an Empty StringJoiner Object to put some data to it. |
953
+
954
+
Note : The Code File and Explanation regarding StringJoiner Class is available in this [link](https://github.com/ackwolver335/Java-Coder/blob/main/str1_join.java).
0 commit comments