This is an extension to below question in StackOverflow as I am not understanding the accepted answer.
How do you determine the type of data contained in a string?
If someone could please give a sample code for below case:
I have a String array as below:
String[] myArray = new String[4];
myArray[0] = "one";
myArray[1] = "2012-02-25";
myArray[2] = "12345.58";
myArray[3] = "1245";
I want something as below:
for(String s:myArray){
if(s is a number){
System.out.println("A number!");
}
else if(s is a float){
System.out.println("A float!");
}
else if(s is a date){
System.out.println("A date!");
}
else if(s is a text){
System.out.println("A text!");
}
}
But I don't know what will come inside the IF conditions to determine the type of data in given String.
Thanks for reading!