0

Hey can anyone help me by telling how to delete the data an array which is inside another array.

eg: alpha[] is an array which has two arrays inside it of length [1-100] and [101-200] now i need to delete only the first array from alpha[].

5
  • 1
    Like alpha[0]=null ? But what do you mean with length [1-100] ? Maybe you should show more code so that the context is clearer. Commented Mar 26, 2013 at 15:58
  • thanks for message. I can add screenshot so I can explain better. But I am not able to do it. I need to have 10 reputation to add images. Getting crazy... Commented Mar 26, 2013 at 16:43
  • A screenshot ? You probably need to add 5 lines of code instead. Commented Mar 26, 2013 at 16:45
  • No my friend. Code is very very distributed. The value to array is a return value of method. And that method is linked to many other methods. I debugged using net beans and took a snap of the array at that instance. Wanna an post to explain better. Commented Mar 26, 2013 at 16:56
  • We don't want to see the real code, we want to see the minimal code that reproduces your problem. Commented Mar 26, 2013 at 17:02

3 Answers 3

1

Arrays are fixed in size, you cannot resize them after creating them. You can remove an existing item by setting it to null:

alpha[0]=null
Sign up to request clarification or add additional context in comments.

1 Comment

I am aware of that. my situation is this, I declared a array as below static byte[] headerPacket; then two arrays are added to it dynamically. I wanna delete one array which is added in first place. I am not able to attach the screenshot, or I can explain it better.
0

Check out the Arrays utility class here.

If you are interested in just getting a sub array out of an array a good way to do that is Arrays.copyOfRange(alpha, 101, 200).

If you have a two dimensional array and you are only interested in one of the "rows" you can do Arrays.copyOf(alpha[1], alpha[1].length)

Comments

0

You can try either of these approaches:

    int[] array = {1,2,3,4,5};
    int[] subArray = new int[2];
    System.arraycopy(array, 0, subArray, 0, 2);
    System.out.println(Arrays.toString(subArray));
    => output: 1,2

    subArray = Arrays.copyOf(array, 2);
    System.out.println(Arrays.toString(subArray));
    => output: 1,2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.