I have this very long array of objects:
public static class __Location {
public __Location(int locationId, String locationDesc) {
this.LocationId = locationId;
this.LocationDesc = locationDesc;
}
public int LocationId;
public String LocationDesc;
}
public static __Location[] LOCATIONS = { new __Location(100, "Afghanistan"), new __Location(110, "Albania"), new __Location(120, "Algeria"),
new __Location(130, "American Samoa"), new __Location(140, "Andorra"), new __Location(150, "Angola"), new __Location(160, "Anguilla"),
new __Location(170, "Antarctica"), new __Location(180, "Antigua And Barbuda"), new __Location(190, "Argentina"), new __Location(200, "Armenia"),
new __Location(210, "Aruba"), new __Location(220, "Australia"), new __Location(230, "Austria"), new __Location(240, "Azerbaijan"),
new __Location(250, "Bahamas"), new __Location(260, "Bahrain"), new __Location(270, "Bangladesh"), new __Location(280, "Barbados"),
new __Location(290, "Belarus"), new __Location(300, "Belgium"), new __Location(310, "Belize"), new __Location(320, "Benin"),
new __Location(330, "Bermuda"), new __Location(340, "Bhutan"), new __Location(350, "Bolivia"), new __Location(360, "Bosnia And Herzegovina"),
new __Location(370, "Botswana"), new __Location(380, "Bouvet Island"), new __Location(390, "Brazil"),
new __Location(400, "British Indian Ocean Territory"), ...
My question is how can I efficiently search for an item in this long array (according to its key value, i.e., LocationId).
locationIdunique?.equals()/.hashCode()and using aHashSet.__Locationto implementComparable<__Location>, or use aComparator<__Location>PascalCase.__Locationshould beLocation.