Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

what method is use for getting the index position of a character of a string in java

// If you want to get the index position of a character in a String, use this method:
.charAt( /*Args int*/ )
// Here's a practial example:
String str = "Grepper";
char ch = str.charAt(0);

// If you want to get the index position of a word/char in a string(a Phrase/Sentence), you could use this method:
.indexOf( /*Args Str*/ )
// Here's a practial example:
String myStr = "This is just an example Sentence";
System.out.println(myStr.indexOf("example"));
Comment

java string character at index

/*
If you want to get the index position of a character in a String,
use this method:.charAt( <index> )
*/  
// Here's a practial example:
String str = "Grepper";
char ch = str.charAt(0);
// output: G 

/* If you want to get the index position of a word/char in a string(a Phrase/Sentence), 
you could use this method:.indexOf( <Args Str> )
Here's a practial example:
*/ 
String myStr = "This is just an example Sentence";
System.out.println(myStr.indexOf("example"));
// output: 16
Comment

PREVIOUS NEXT
Code Example
Java :: how to convert string array to int in java 
Java :: java how to get all threads 
Java :: java stream distinct by atribute 
Java :: keytool error: java.io.FileNotFoundException: c:UsersUSER_NAMEupload-keystore.jks (The system cannot find the path specified) 
Java :: reading from a text file in java 
Java :: java quotes in string 
Java :: how to read file from console in java 
Java :: java srting array to string 
Java :: conversion of string to integer in java 
Java :: how to check if string is double or not in java 
Java :: print values of bst java 
Java :: activitycompat.requestpermissions not working 
Java :: java convert a string to char[] 
Java :: setting scale to big decimal java 
Java :: How to efficiently find the next greater permutation of a list of values, in Java? 
Java :: Failed to collect dependencies at net.sf.jasperreports:jasperreports:jar:6.2.0 
Java :: imageview height based on screen size 
Java :: get raondom from array java 
Java :: java nested loop 
Java :: check how many times a character appears in a string java 
Java :: how to move a marker on google maps in android studio 
Java :: how to find the length of a string in java without using length function 
Java :: how to right align in java 
Java :: spigot dispatchcommand 
Java :: how to initialize array in java with 0 
Java :: how to convert primitive int to Integer in java 
Java :: generating random number 
Java :: java for loop increment by 3 
Java :: find elements in selenium 
Java :: spring boot MVC config 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =