Created
December 13, 2012 02:45
-
-
Save nathanchen/4273599 to your computer and use it in GitHub Desktop.
JAVA - 插入元素到一个无序的数组里
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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