Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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);
Comment

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"
Comment

PREVIOUS NEXT
Code Example
::  
::  
::  
::  
::  
Java ::  
::  
::  
::  
Java ::  
::  
::  
::  
::  
::  
::  
::  
::  
::  
::  
Java ::  
::  
::  
Java ::  
::  
::  
::  
::  
::  
::  
ADD CONTENT
Topic
Content
Source link
Name
9+9 =