Split Array with Comma ( Empty data in String)
24365onlineservices
05:55
I got an issue to split String in java when there is empty data in String after comma.
String testStr = "one,,";
Spliting like below solved my problem
String[] result = testStr.split("\\,", -1);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public class SplitArray { public static void main(String[] argv) { String testStr = "one,,";
System.out.println("Original string : " + testStr); System.out.print("\nSplit at commas: "); String[] result = testStr.split("\\,", -1); System.out.print("Array Length : "+ result.length); for(int i=0;i<result.length; i++) { System.out.print("\n position:"+i +" "+ result[i]); } } }
|
';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();