Knowledge about arraylist and map

Source: Internet
Author: User

October 17, 2014 16:39:01

1. How to obtain the index value of a data entry in the arraylist?

In the arraylist of Multiple object stores, if you only know one of the attributes of an object, how do you get the index value of this object in the arraylist?

For example, a person class has three attributes (string name, string sex, int age)
Person p1 = new person ("Zhang San", "male", 20 );
Person P2 = new person ("Li Si", "male", 22 );
Person P3 = new person ("Wang Wu", "male", 24 );

Then these objects are stored in the arraylist set. If you only know the name "Li Si" (without knowing the gender and age ), how to obtain the index value (1) of the "Li Si" object in the arraylist set )?

Solution:

For (INT I = 0; I <list. size (); I ++) {If ("Li Si ". ES (list. get (I ). getname () {return I; // I is the index }}

 

Knowledge about arraylist and map

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.