相关疑难解决方法(0)

如果Set包含具有某些字符串值的对象,如何检入java?

我有一组对象.每个对象都有String值.

我需要选择所有this值等于"方向"的对象.

是否可以不迭代集合?

谢谢.

java string iterator map set

19
推荐指数
3
解决办法
7万
查看次数

如何根据其他微调器在两个不同活动中的位置来改变微调器的位置

我在两个不同的活动中有两个android spinner下拉列表.但是两个微调器都有来自同一个sourec的相同数据.我想根据第一个活动的位置改变第二个Activity的位置.如何解决这个问题?

更新的代码:

第一项活动:

public class ServiceRequest extends BaseActivity implements OnItemClickListener {
    private List<Item> customerList = new ArrayList<Item>();
    private SpinnerAdapter adapter;
    public static final String EXTRA_INTENT_CUSTOMER_LIST  ="extra_intent_customer_list";

    public static final String EXTRA_INTENT_SELECTED_ITEM = "extra_intent_selected_item";
    private List<Item> items;
    Spinner spin;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getLayoutInflater().inflate(R.layout.service_request, frameLayout);

       ;


    );
                    System.out.println("Selected item "    Button login = (Button) findViewById(R.id.booking);

        final String message = autoCompView.getText().toString();
        //Create the bundle


        login.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v) {
{

                    if(customerList.isEmpty()) return;
                    Item selectedItem = …
Run Code Online (Sandbox Code Playgroud)

android listadapter android-intent android-spinner android-bundle

14
推荐指数
1
解决办法
1500
查看次数

ArrayList 循环只输出最后一项

我正在尝试遍历一个 ArrayList,并将每个索引值与默认值进行比较,如果索引值与默认值匹配,我想返回 true,唯一的问题是,它总是只对索引项返回 true被添加。由于我的类没有 main 方法,因此我在类构造函数初始化期间添加了这些值。

  public class CountryFinderImpl implements CountryFinder{

    List<String> Countries = new ArrayList<String>();



    public CountryFinderImpl() {

        Countries.add("canada");
        Countries.add("japan");
        Countries.add("usa");

    }

    @Override
    public boolean forWeather(String country) {
        // TODO Auto-generated method stub
        country = country.toLowerCase();
        boolean c=false;


                for(int i=0; i<Countries.size();i++) {
                    if(Countries.get(i).equals(country)) {
                        //System.out.println(country+"Weather available");
                        c=true;
                    }else {
                        //System.out.println(country+"weather unavilable");
                        c=false;
                    }

                }


        return c;
    }

}
Run Code Online (Sandbox Code Playgroud)

country 参数是从另一个类传递的,该类从用户那里获取国家/地区值。

java loops for-loop arraylist

2
推荐指数
1
解决办法
36
查看次数

如何比较ArrayList中的对象属性?

我对 Java 相当陌生,我已经用尽了所有当前资源来寻找答案。我想知道是否可以访问对象第一个属性来查看它是否与特定整数匹配?

例如,我尝试通过产品 ID 搜索来获取数据库中的产品。因此,如果我创建两个产品,例如Product ipad = new Product(12345, "iPad", 125.0, DeptCode.COMPUTER);Product ipod = new Product(12356, "iPod", 125.0, DeptCode.ELECTRONICS);(我已在下面包含此 Product 类),并将它们添加到 Arraylist 中,例如,List<Product> products = new ArrayList<Product>();如何循环此 ArrayList 以便通过其 ID 查找该产品?这是我正在研究的方法:

List<Product> products = new ArrayList<Product>();


@Override
public Product getProduct(int productId) {
    // TODO Auto-generated method stub
    for(int i=0; i<products.size(); i++){
        //if statement would go here
        //I was trying: if (Product.getId() == productId) {
        System.out.println(products.get(i));
    }
    return null;
}`
Run Code Online (Sandbox Code Playgroud)

我知道我可以在 for 循环中包含条件语句,但我不知道如何访问 Product …

java database arraylist

1
推荐指数
1
解决办法
4万
查看次数

比较具有多个值的字符串

我想在 Ireport 中用 java 添加以下条件:

Field.equals("red" or "bleu" or "black" or "....") ? "yes" : "no"
Run Code Online (Sandbox Code Playgroud)

我必须使用吗

Field.equals("..")||$F{color}.equals("..")
Run Code Online (Sandbox Code Playgroud)

我有一个很长的清单。有没有其他的表达方式?

jasper-reports

0
推荐指数
1
解决办法
64
查看次数

找到第一次出现而不使用循环

我有一个名为的对象类Store,其属性为"year":

public class Store{
     public int year;
     ...
}
Run Code Online (Sandbox Code Playgroud)

然后,在另一个班级我得到了一个商店列表:

List<Store> stores = getAllStores();
Run Code Online (Sandbox Code Playgroud)

我想从列表中得到第一次出现的商店,其年份是2002而不使用for循环或while循环.可能吗?

java java-ee

-1
推荐指数
1
解决办法
137
查看次数