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"
4
5
String string = "Hai,Hello,How,are,you";
String[] bits = string.split(",");
String lastWord = bits[bits.length - 2];
tvs.setText(lastWord);
Thank you!
5
0
Are there any code examples left?
New code examples in category Java