Posts

Showing posts with the label arraylist

Making a 2 dimensional list/matrix with different number of columns for each row

Making a 2 dimensional list/matrix with different number of columns for each row I would like to make a list or matrix that has a known number of rows(3), but for each row the number of elements will be different. So it could look something like this: [[4, 6, 8], [1, 2, 3, 4], [0, 2, 3, 4, 8]] Each row will have a known maximum of elements(8). So far I have tried the following: Sets1=np.zeros((3,8)) for j in range(3): Sets1[0,:]=[i for i, x in enumerate(K[:-1]) if B[x,j]==1 or B[x+1,j]==1] I want this because I want to have a list for each j in range(3) over which I can do a for loop and add constraints to my ILP. Any help will be greatly appreciated! Final expected output for the given sample? – Divakar Jun 29 at 8:35 You shouldn't call that a matrix because matrix is a rectangular array of numbers. It's...

Save ArrayList to SharedPreferences

Save ArrayList to SharedPreferences I have an ArrayList with custom objects. Each custom object contains a variety of strings and numbers. I need the array to stick around even if the user leaves the activity and then wants to come back at a later time, however I don't need the array available after the application has been closed completely. I save a lot of other objects this way by using the SharedPreferences but I can't figure out how to save my entire array this way. Is this possible? Maybe SharedPreferences isn't the way to go about this? Is there a simpler method? ArrayList SharedPreferences SharedPreferences You can find Answer here : stackoverflow.com/questions/14981233/… – Apurva Kolapkar Oct 25 '16 at 10:10 this is the complete example go through the url stackoverflow.com/a/41137562...