I have a string and want to sub-string till 3rd occurrence of "," . I can achieve this using Array. here is the code
String test ="hi,this,is,a,string.";
String[] testArray = test.split(",");
System.out.println(testArray[0]+","+testArray[1]+","+testArray[2]);
Output is :- hi,this,is
Is there anyway to achieve the same using "substring(0, text.indexOf(","))" method.Second thing is there could be some instances where there is no "," in the string and i want to handle both scenarios
Thanks in advance