If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

The idea of the latter is better, because it is more reusable...it would support any number of items, rather than just 3, which you would have to recode for another program that needs more than three items. However, I don't think you should name a method 'try', as that is a Java keyword used in exception handling. Not necessarily an error, but it's bad practice.

major: i have a typo there, you're rite, it should be a ")", not a "}"

pirate: thanks for the suggestion, so it's ok if i use the second lines of code? will i get memory lack or
something? because i don't really understand of the keyword "new" is. isn't it to make a new instance?

and about that "try" keyword hehe, i wrote it myself, not copy pasting it from my code. so it's a
mistake.

pirate: thanks for the suggestion, so it's ok if i use the second lines of code? will i get memory lack or
something? because i don't really understand of the keyword "new" is. isn't it to make a new instance?

It should be fine, you don't have to worry so much about the memory leaks in Java, because Java has automated memory management, unlike some other OOP languages. Any values you've set up in RAM will be cleaned out by the garbage collector a few milliseconds or so after no reference variables are pointing to them. The new operator is typically used to make an instance, such as:

Foo f = new Foo();
myMethod(f);

but, you can also use it to create objects on the fly without a variable, the way you are doing it with your code, such as;