we can learn to get the character at the given index within the String
Approach Steps 🤔
Code bit :
Practice Code in LeetCode PlayGround 🥇🥇🥇🥇
Source code :
public class MainClass {
public static void main(String[] args) throws IOException {
// take a Given string
String original = "Java Code Practice";
// Print original string for reference
System.out.println( "Given original string :--"+ original+"\n");
// chatAt method : it is used for find out character at given index
// hold it by int type
int givenIndex = original.charAt(1);
// while display time type cast to char
// Print the character at given index
System.out.println( "the character at zero index :-- "+(char)givenIndex);
}
}
Result :
Learnt from this Code Bit :
- charAt() method: this method is used for getting a character at a given index from the original string. for the above example gave an index at 1 in charAt(1) method so got the result "a".
- One more thing "\n" used for the next line
- type casting is done int to char so got it from the above code bit.
Thank you!
:)Sagar R G