Last active
March 26, 2023 13:45
-
-
Save sametaybaz/37c342c4c92da3cd377e3d1d05e221fd to your computer and use it in GitHub Desktop.
Java Notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Java working notes about important points |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create char array from String | |
char[] charArray = str.toCharArray(); => string to char array | |
char[] reversedArray = new char[charArray.length]; => create new char array ( str.length() can use instead charArray.length ) | |
*************************************************** | |
// Using mutable StringBuilder class instead immutable String class when manipulate String | |
StringBuilder builder_str = new StringBuilder(str); | |
String reversed_str = builder_str.reverse().toString(); | |
return reversed_str; | |
in one line => return new StringBuilder(str).reverse().toString() | |
*************************************************** | |
// Manipulate with replaceAll() method to string and Passed or removed whatever chars | |
input => "fun123&!! time" | |
String sen_replaced = sen.replaceAll("[^a-zA-Z0-9 ]", ""); => output: "fun123 time" | |
String[] words = sen_replaced.split(" "); // {"fun123","time"} | |
*************************************************** | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment