I'm wondering if it's possible to choose a few objects from an array to use, like String[1-4] or something, where you use strings 1 to 4, or if I'll have to use a more complicated way of doing it, like getting the length of the array and using a for-loop for the objects I want. I'm pretty sure there's an answer somewhere on the web, but I have actually no idea what to search for.
Right that. Code:java //print items 1 to 4 (inclusively)for(int i=1; i<=4; i++){System.out.println(items[ i].toString());}
mine-care It's easy, but nowhere near as easy as Object[x-y]. JWhy That's the simplest solution? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
This is a array, for is mostly used in arraylist. In String[] you do string[1] In arraylist you do arraylist.get(1);
Anrza If you are using a List Object, then you can use the subList method but if you are just using a plain Array, then there is no fancy method to do it for you.