java - What kind of collection class to get position in array? -


I have the following status and I am seeking a suggestion to "correct" in Java.

I have an ArrayList which has a list of objects (let's call it A object),

Every object Contains two other objects,

  • Object X
  • More items Y

    squared a diagram

    Now one of my method is a method object Y Gives examples.

    Now I need an index in ArrayList , where I get the same thing.

    How do I do without horrible loops?

    I can use it instead of ArrayList

    A more natural option for the problem to keep your objects in a map, using your Y as a Y and keeping it as an object value:

      Maps & lt; Y, A & gt; Map = new hashmap & lt; & Gt; (); Void placed (AA) {map.put (a.Y, A); } A getA (y y) {back to map.get (y); }   

    Note that the map stores an A only for each specific value of y. It is not suitable to associate Multiple A with one Y. For this, you will use a set map or something similar.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -