Hi All,

I am trying for a logic that i have some emp ids as a string seperated by commas and i need the substring of emp ids as below.
Can any one help in splitting the string as below.

public static void main(String args[]) {
        
         String empId = "1,2,3,4,5,6,7,8,9,10";
        int i;
           int count = 9;

           for (i = 0; i <= count; i = i + 3)
           {
             System.out.println("Emp IDs are : " +empId);
           }
}

 

              Result is:

Emp IDs are : 1,2,3,4,5,6,7,8,9,10
Emp IDs are : 1,2,3,4,5,6,7,8,9,10
Emp IDs are : 1,2,3,4,5,6,7,8,9,10
Emp IDs are : 1,2,3,4,5,6,7,8,9,10

 

But i want the result like:


Emp IDs are : 1,2,3
Emp IDs are : 4,5,6
Emp IDs are : 7,8,9
Emp IDs are : 10

 

thanks for your help.

FacebookTwitterLinkedin
Pin It
Joomla Tutorials for Beginners