/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
        List < List < Integer > > listOfLists =
                List.of(
                        List.of( 1 , 2 , 3 ) ,
                        List.of( 4 , 5 ) ,
                        List.of( 6 , 7 , 8 )
                );
        OptionalInt longestLength = listOfLists.stream().mapToInt( List :: size ).max();
        int limit = longestLength.orElse( 0 );

        int initialCapacity = listOfLists.stream().mapToInt( List :: size ).sum();
        List < Integer > results = new ArrayList <>( initialCapacity );
        for ( int i = 0 ; i < limit ; i++ )
        {
            for ( List < Integer > listOfIntegers : listOfLists )
            {
                try
                {
                    Integer integer = listOfIntegers.get( i );
                    results.add( integer );
                }
                catch ( IndexOutOfBoundsException e )
                {
                    // Do nothing. Swallow exception. We expect to fall out of bounds on shorter lists.
                }
            }
        }

        System.out.println( "listOfLists = " + listOfLists );
        System.out.println( "longestLength = " + longestLength );
        System.out.println( "limit = " + limit );
        System.out.println( "results = " + results );
	}
}