Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save nathanchen/4273599 to your computer and use it in GitHub Desktop.

Select an option

Save nathanchen/4273599 to your computer and use it in GitHub Desktop.
JAVA - 插入元素到一个无序的数组里
public class InsertingElementsToArray {
public static void insertUnsortedArray(String toInsert) {
String[ ] unsortedArray = { "A", "D", "C" };
String[ ] newUnsortedArray = new String[unsortedArray.length + 1];
System.arraycopy(unsortedArray, 0, newUnsortedArray, 0, 3);
newUnsortedArray[newUnsortedArray.length - 1] = toInsert;
System.out.println(Arrays.toString(newUnsortedArray));
}
public static void main(String[ ] args) {
insertUnsortedArray("B");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment