1) I am unable to read the elements from the list Column Wise because the size of the Column is variable.
2)I have 10 Database and have stored each of these 10 database information in a list.Each list in the database can have variable length.
having variable data.
I am able to insert the elements in the list. But I am not able to read the elements from the list Column Wise but the rows are fixed.
For Example:Let's say the elements can be any.
1 2 3
1 2 3 4 5
1 2
1 2 4
I need the output as 1,1,1,1,2,2,2,2,3,3,4,4,5
Can anyone guide me How can I get?
MyUnderstanding
I tried the following approach and Coded like this
I MyCode:
int ar[][] = new int[10][]; //Created a 2Dimensional Array
//The Size of the row is fixed but not for Columns(as it is variable)
ArrayList<Object> al = new ArrayList<Object>();
ArrayList<<Object> al1 = new ArrayList<Object>();
ArrayList<Object> al4 = new ArrayList<Object>();
for (int j = 0; j < ar.length; j++) //This loop is for generating each database
{
System.out.println("Enter the Size of the list" + j);
String s1 = sc.next();
int i = Integer.parseInt(s1);
for (int k = 0; k < i; k++) //This loop is for generating the elements size inside each database
{
System.out.println("Enter the Elements of the list" + j);
String s2 = sc.next();
al1.add(s2); //I store these elements in a list
ar[i] = new int[al1.size()];
al.add(al1); //Finally store a list in a SeperateList
}
}
System.out.println("Reading each elements of the ArrayList");
MAIN PROBLEM
ListIterator ltr = al.listIterator(); // Used ListIterator to extract
// each
// List from the 10 list.
for (int i = 0; i < 10; i++)
{
for (int l = 0; l < ar[i].length; l++)
{
while (ltr.hasNext()) // A list AL having 10 Databases.
{
ArrayList a0to9 = (ArrayList) ltr.next();// I have taken 1 listfrom the 10 Databases.
ListIterator ltr1 = a0to9.listIterator(); // Used ListIterator to extract each Element from the List.
while (ltr1.hasNext()) // If the first List contains the elements (the elements are stored in the form of list)
{
ArrayList elements = (ArrayList) ltr1.next(); // If the list has elements we can extract that Object
al4.add(elements); //And store the elements in another list
break;
}
}
}
}
But I am getting the folloing Output
Output:
Exception in thread "main" java.lang.NullPointerException
at LockWaitTimeoutTest.main(LockTest.java:48)
Can anyone guide me how can I solve this problem.
Thankx in Advance :)