Java finds a specific letter for the first time

I am developing a program in Java I need to find specific text in the string Suppose the string is' hawaiie ' I need to find'd 'and amp‘ E’. If 'e' appears first, 'e' must be returned, and if'd 'appears first,'d' must be returned String 'hawaiie', because 'e' is the first letter 'e' that must be returned I tried the following code for this, but it only returns the position of the letter, not the letter itself

String str1 = new String("Hawaiee");
System.out.println(str1.indexOf('e');

Solution

Try this Code:

String str = new String("Hawaede");
    int a=str.indexOf('d');
    int b=str.indexOf('e');
    if(a!=-1 && a<b) 
    {
        return 'd'
    }
    else if(b!=-1) return 'e';
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>