Last active
June 8, 2019 21:38
-
-
Save xiaoxipang/efe642d5818174275c874ced9115de85 to your computer and use it in GitHub Desktop.
Some Basic Operation for Algorithm in Java
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
| /** | |
| * String manipulation | |
| */ | |
| // 1. Parse string with delimiter | |
| String phone = "012-3456789"; | |
| String[] output = phone.split("-"); | |
| // Note: When split string with delimater with "." or " ", instead of directly using them, we have to using the double slash | |
| // to help, i.e. | |
| String[] digits = version.split("\\."); | |
| String[] words = sentence.split("\\s+"); | |
| // 2. Convert string to int | |
| String number = "10"; | |
| int result = Integer.parseInt(number); | |
| // 3. Substring - (inclusive, exclusive) | |
| String s="SachinTendulkar"; | |
| s.substring(6);//Tendulkar | |
| s.substring(0,6);//Sachin | |
| // 4. Get the string lenth | |
| s.length();//15 | |
| // 5. Convert char arrary to String | |
| char[] charArray = new char[3]; | |
| String convertedStr = new String(charArray); | |
| // 6. Convert int to char | |
| int digit1 = 1; | |
| char convertedChar = (char)(digit + '0'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment