Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Is it easier writing this:
- String var0 = "asd";
- String var1 = "sdf";
- String var2 = "dfg";
- and calling with:
- var0, var1, var2
- Or:
- String[] vars = {"asd","sdf","dfg"};
- and calling with:
- var[0], var[1], var[2].
- It's less typing, looks neater and helps with categorisation.
- And a quote from a friend: "It's infinitely more efficient at storing, sorting, manipulating and outputing data"
- It's also kind of explained in this tutorial, I think: http://www.youtube.com/watch?v=L06uGnF4IpY
- They're also amazing when you get to loops. Take this, for instance:
- String[] words = {"test","yes","no","maybe","upside down","downside up","etc."};
- for(int i; i < words.length; i++) {
- System.out.println(words[i]);
- }
- Run this program, and you automatically print all values in the array words[] to the screen. The alternative is:
- String[] words = {"test","yes","no","maybe","upside down","downside up","etc."};
- System.out.println(words[0]);
- System.out.println(words[1]);
- System.out.println(words[2]);
- System.out.println(words[3]);
- System.out.println(words[4]);
- System.out.println(words[5]);
- System.out.println(words[6]);
- Imagine if I wasn't even using an array to store the values, but seperate variables. I'd also have to have
- String word1 = "test";
- String word2 = "yes";
- etc.
- The second method doesn't automatically print new values either, you'd have to add a new System.out.println.
- And sorry if I just confused the hell out of you, I don't know if you've done loops and such yet.
Advertisement
Add Comment
Please, Sign In to add comment