java - Using List, how would I change this code as using List -
So I have this code down, and I have to instantly put my array in a new array. Int [] Copy all data from myArray data. Set numemoves equal to 0. Array with input to values from user So this code is done by using only int and bus = signs and new ones, but now I need to change it to use "list" and I do not know what this list is and how to use it is. So what do I need to help is the list on Java and how I will use it from the list. Thank you, and telling me how it works, thank you!
Public class extinction {Private Ent [] myArray; Private int max; Public extinction (int [] data) {myArray = new int [data.length]; {MyArray [n] = data [n] for (int n = 0; n & lt; data lamps; n ++); } NumMoves = 0; First, the original array copy method can be written this way. int [] myArray = new int [data.length]; System.arraycopy (data, 0, myArray, 0, data.length);
And then, the solution will be
public list & lt; Integer & gt; CopyToList (int [] data) {List & lt; Integer & gt; List = New Arrestist & lt; Integer & gt; (); For (int i = 0; i & lt; data; lang; i ++) {list.add (data [i]); } Return list; }
or
public list & lt; Integer & gt; CopyFromToList (list & lt; integer & gt; data) {new ArrayList & lt; Integer & gt; (Data); }
Comments
Post a Comment