Can you tell me please what method should I use and how.
Note: before you read this, i'm giving out some explanations based on what i saw from your questions. But these explanations are nowhere close to all the things that you'll be able to do. I'd recommend you to look into a book for a wider approach to Java, and algorithms. I don't know what "level" are you in programming, so i explained it to you as if you were a beginner, so i hope you don't die of boredom with my explanations.
It's not a matter of a specific method, as it is a matter of you creating your own methods. When creating a class you're outlining something. It is like answering what? and how?. I think of it this: i you were to build a hardcore metal grinding guitar, you'd first must outline the shape, size, weight, but also the technical specifications (pickups, bridge, fretboard) and with them . You'd end up whit a piece of paper with what is and what can your guitar do but not with a guitar.
So you have what the guitar is (shape, size, ...) and how you're going to achieve the metal sound (ebony fretboard with EMG humbucking pickups). Back to the class, you'll be outlining an object with atributes (what) and methods (how). So, if you wish to create an object you have to define attributes and methods.
Again, i think you sould get your hands on some book about java.
take care