2
ipaddresses = IpAddresses.GenerateIps();

The array contain 56 items. I want item in index 2 to remove it to the end of the array. So the content in index 2 will be now in index 56. The array size will not change only the order of the items. Item 2 will be in place 56. So now i think index 3 will be index 2.

1

2 Answers 2

4

You can use System.arraycopy. This is similar to what happens when you remove an element from an ArrayList, only in your case you are moving the removed element to the end :

E element = elementData[index]; // get the element to be removed
int numMoved = elementData.length - index - 1;
// move all the elements that follow the moved element
if (numMoved > 0)
    System.arraycopy(elementData, index+1, elementData, index, numMoved);
// put the moved element at the end
elementData[elementData.length - 1] = element;

Here elementData is the array and we move the element at the index position to the end.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

String text = "Cool";    
text = text.replace(text.charAt(1), "") + text.charAt(1);

1 Comment

While this code may answer the question, it would be better to explain how it solves the problem without introducing others and why to use it. Code-only answers are not useful in the long run.

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.