0

给定和字符串数组,例如:

userMail usermail = new userMail();
List<String> data = new ArrayList<String>();

对象 userMail 的定义如下:

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlRootElement;


@XmlRootElement
public class userMail {
    public userMail(){

    }

    public List<String> email = new ArrayList<String>();

    public List<String> getEmail() {
        return email;
    }

    public void setEmail(List<String> email) {
        this.email = email;
    }

所以这就是我迷路的地方:给定一个来自客户的电子邮件地址,遍历一个数组并找到它。如果存在,则返回一些与此电子邮件地址关联的数据,并使用 REST 将其发布回客户端。

即使是高级概念也将不胜感激。谢谢

4

2 回答 2

0

Its better to use HashMap or any Map construct which will clear the hastle of setting up a search algorithm.

For example

public static void main(String[] args)
{
    HashMap<String,String> xdr = new HashMap<String, String>();
    xdr.put("bdx@atr.com", "Border line Statement");
    System.out.println(xdr.get("pdf"));//output returned is null
            String valx = xdr.get("bdx@atr.com");
    String valy = xdr.get("pdf");
    if(valy == null)
        System.out.println("This is null value" + valy);
    if(valx == null)
        System.out.println(valx);
}

in case the key is not found null is returned. you can check the value returned against null to proceed further.

then return some data that is associated with this email address

you can even store this data you want to return as the value store in the HashMap for the key.

于 2013-11-07T01:28:06.827 回答
-1

尝试这个:

public email checkForEmail(testEmail)
{
    for(int x = 0; x < emailList.length-1; emailList--) //searches through list of emails
    {
        if(emailList[x].equals(testEmail)) //if current index position equals email you search for
            return emailList[x]; //return that email
    }
    return null; //returns null if the email address wasn't contained
}

您可以编辑 if 语句来比较您选择的电子邮件的任何变量。

于 2013-11-07T00:45:38.947 回答