Answers for "write a code to print second last word of input string"

0

write a code to print second last word of input string

String string = "Hai,Hello,How,are,you";
String[] bits = string.split(",");
String lastWord = bits[bits.length - 2];
tvs.setText(lastWord);
Posted by: Guest on April-12-2021
0

write a code to print second last word of input string

String string = "Hai,Hello,How,are,";
String[] bits = string.split(",", -1);
 ↓
bits[]…{ "Hai","Hello","How","are","" }
bits[bits.length-2]…"are"
Posted by: Guest on April-12-2021

Code answers related to "write a code to print second last word of input string"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language