problems with saving data to arraylist
in
Programming Questions
•
1 year ago
I receive udp data in this method , I save the data into an array-list but because I have a loop in every iteration the content of arraylist changed , and it does not save all of the data that comes. I don't know how should I delete and change the main loop .
Is there any other way to add new items to array list without deleting the items that saved there from the last iteration ?
- void receive(byte[] data, String HOST_IP, int PORT_RX) {
- receivedFromUDP ="";
- for (int i = 0; i < data.length; i++) {
- receivedFromUDP += str(data[i]) + " ";
- int j = 0 ;
- while ( j<data.length ) {
- if ( data[2*j+2] >= 0 ) {
- float[] bin2 = new float[] {
- (unbinary(binary(data[2*j+3])+
binary(data[2*j+2])+binary( data[2*j+1])+binary(data[2*j]) )) - };
- balls.add(unbinary(binary(
data[2*j+3])+binary(data[2*j+ 2])+binary(data[2*j+1])+ binary(data[2*j]))); - println("array list is" + balls);
- }
- }
- j = j + 2;
- }
- }
- }
1