I have some text
"Summary : Daily Monthly Yearly"
"Amount : $1,401,508,225.38 $34,132,889,672.53 $334,088,690,177.34"
My question here is that how do i store this amounts in their respective strings i.e. Daily, Monthly, Yearly ?
I have some text
"Summary : Daily Monthly Yearly"
"Amount : $1,401,508,225.38 $34,132,889,672.53 $334,088,690,177.34"
My question here is that how do i store this amounts in their respective strings i.e. Daily, Monthly, Yearly ?
As per your comment you said you have array of Strings that contains three amounts and as per your question, you want to store in respective Strings. You can use for loop and store in HashMap.
First get your time in array as following:
String textWithTime = "Daily Monthly Yearly";
String[] timearray = textWithTime.split(" ");//note the space inside double quotation
If you have amount of money in a string, then do the following as well
String[] amountarray = textWithAmount.split(" ");//note the space inside double quotation
Do as following:
//Make an object of HashMap here
HashMap<String, String> hashMap = new HashMap<String, String>();
for(int i=0;i<stringarray.length();i++){
hashMap.put(timearray[i], amountarray[i]);
}
And to retrive the key and values back you can do the follow:
for (Map.Entry<String, Object> entry : hashMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
//Use these key and values
}
If your question is about how to split strings, see split() method of String class. If it is more about how to structure resulting data, you may want to do as below:
Create a enum and a class:
public enum Period {
DAILY,
MONTHLY,
YEARLY;
}
public class Income {
private Period p;
private double money;
public Income (Period p, double money) {
this.p = p;
this.money = money;
}
....
// getters, etc
}
then you could use it like this:
Income daily = new Income (Period.DAILY, 1401508225.38);