Skip to content

Instantly share code, notes, and snippets.

@xnorcode
Last active August 29, 2018 16:15
Show Gist options
  • Save xnorcode/249746906a941edc89792ac1b383695f to your computer and use it in GitHub Desktop.
Save xnorcode/249746906a941edc89792ac1b383695f to your computer and use it in GitHub Desktop.
Simple Array Manipulation in Java
...
// Method 1
// create array of already known numbers
int[] numbers = {10,2,5,8,37,6};
// printing all numbers
for(int i = 0; i < numbers.length; i++){
System.out.println(numbers[i]);
}
// Method 2
// create an empty array with 3 slots
String[] strings = new String[3];
// input strings to the array
for(int i = 0; i < 3; i++){
strings[i] = "String"+i;
}
// printing the strings
for(String s : strings){
System.out.println(s);
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment