given an array String [] stringtest= new String[]{"dog","bark","1","m"};
how could I store the fourth element as a character? The reason being that I need to compare the last element to a character inside an if statement.
I need if(stringtest[3]=='m')
to work
you can convert string to char array
char[] ch= stringtest[3].toCharArray();
if(ch[0]=='m')
or you can use charAt method
if(stringtest[3].charAt(0)=='m')
you can use toCharArray()
method of string
this would work, although not clear why you want it like that
if( stringtest[3].toCharArray()[0] == 'm')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.