A
A
andwin2017-01-08 18:59:32
Java
andwin, 2017-01-08 18:59:32

How to get the first letter from a variable?

There is a variable of type String. How to find out what is the first letter in it?
For example, there is a variable s with the value "Hi". You need to find out the first letter (in this case it will be "P"). How to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2017-01-08
@romanbel

Use String.charAt() .

M
Maximus, 2017-01-17
@MaximusWork

char firstLetter = s.charAt(0);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question