vendredi 17 avril 2015

Why i'm getting a null string when i try to add the splitted string?

I have splited a string and from the recieved string i am trying to form a word everything is comming fine but everytime i get null string in the first index why?


Here is my code:



String assetClasses = "Gold:Stocks:Fixed Income:Commodity:Interest Rates";
String[] splits = assetClasses.toString().split(":");

//System.out.println("splits.size: " + splits.length);
String ab = null;
for(int i=0; i<splits.length;i++){
System.out.println(splits[i]);
ab+=splits[i];
}
System.out.println(ab);


The output:


Gold Stocks Fixed Income Commodity Interest Rates


nullGoldStocksFixed IncomeCommodityInterest Rates


Aucun commentaire:

Enregistrer un commentaire