0
String to array
How to String =“1230.5789”; To String[] list={“1”,”2”,”3”,”0.5”,”7”,”8”,”9”}
3 Answers
0
hamid try this:
import java.util.*;
public class test
{
public static void main(String[] args)
{
String str ="1230.5789";
//String[] list={“1”,”2”,”3”,”0.5”,”7”,”8”,”9”};
List<String> list = new ArrayList<String>();
for(int i =0; i<str.length();i++){
if (i<str.length()-1){
if (str.charAt(i+1)!= '.')
list.add(str.substring(i,i+1));
else {
list.add(str.substring(i,i+3));
i=i+2;
}
}
else
list.add(str.substring(i,i+1));
}
System.out.println(list);
}
}
0
see output in my question
- 1
Use loop to convert into character array by traversing each charecter of string.
Or else use predefined function like
String str="12340.567";
char array[] =str.toCharArray();