Q: How can I split a string by a delimiter in Java? I want to make a simple program that can convert currencies and weights, etc. The only problem is that I don't know how to separate a string so that I can get each individual word.
So, if I have the string "200 GBP USD", how can I separate it so that I get
int currency = 200;
String currencyFrom = "GBP";
String currencyTo = "USD";


A: Just split the string using the String.split function.
String[] Parts = input.split(" ");
if(Parts.length>2)
{
    int currency = Integer.parseInt(Parts[0]);
    String currencyFrom = Parts[1];
    String currencyTo = Parts[2];
}


A: You can use the function split:
String[] words = yourString.split(" ");
int currency = Integer.parseInt(words[0]);
String currencyFrom = words[1];
String currencyTo = words[2];

