I have two String: "I am a Beginner", "Hello Dear App Developer" How can I get only the first two words using Java "I am" "Hello Dear"
String TextOne = "I am a Beginner"
String TextTwo = "Hello Dear App Developer"
I need only "I am" and "Hello Dear"
CodePudding user response:
You can split string by space(" ")
String TextOne = "I am a Beginner";
String[] strList = TextOne.split(" "); //["I", "am", "a", "Beginner"]
String finalTextOne = strList[0] " " strList[1];
Log.e("finalTextOne: ", finalTextOne); // It will print "I am"