Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How to get first character of string? [closed]

Tags:

java

string

How to get first character of string?

string test = "StackOverflow"; 

first character = "S"

like image 842
user1710911 Avatar asked Sep 24 '14 07:09

user1710911


People also ask

How do you check if the first letter of a string is a certain letter?

Using the isDigit() method Therefore, to determine whether the first character of the given String is a digit. The charAt() method of the String class accepts an integer value representing the index and returns the character at the specified index.

How do you get the first character of string Kotlin?

Kotlin string indexing We can get specific characters from a string with indexing operations. The example shows how to get the first and last characters of a string. It uses indexing operations and alternative string methods. The indexes start from zero; therefore, the first character has zero index.

How do you get a sub string out of a string?

You call the Substring(Int32, Int32) method to extract a substring from a string that begins at a specified character position and ends before the end of the string. The starting character position is a zero-based; in other words, the first character in the string is at index 0, not index 1.


2 Answers

String test = "StackOverflow";  char first = test.charAt(0); 
like image 134
Karakuri Avatar answered Sep 28 '22 05:09

Karakuri


Another way is

String test = "StackOverflow"; String s=test.substring(0,1); 

In this you got result in String

like image 42
M D Avatar answered Sep 28 '22 05:09

M D