【问题标题】:how to get a string value from java list如何从java列表中获取字符串值
【发布时间】:2017-12-11 06:22:10
【问题描述】:

我想选择列表中的一个。列表包含 五个值。**我想从列表中找到一个值。当列表有 **importer 时,我想做一些事情。我给了我的绳子,我创建了一个名为 roleosuser 的列表。如何检查roleosuser列表是否有进口商。当它有进口商时我想做某事..我该怎么做

@RequestMapping(path = "/view/all/posted-applications/importer")
public String viewallApplicationofIMPORTER(Model model) {
    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    long userId = 0;
    List <String> roleosuser;
    if (principal != null && principal instanceof AuthenticatedUser) {
        AuthenticatedUser auth = (AuthenticatedUser) principal;
        userId = auth.getUserId();
        roleosuser= auth.getUserRoles();

        if(roleosuser.get(0)) {
            System.out.println("importer equals "+roleosuser);
        }
        model.addAttribute("userID", userId);
    }
    return "applicationManageIMPORTER";
}

我想从我的列表中获取“IMPORTER”值。 List 具有进口商和代理价值。如何做到这一点?

【问题讨论】:

  • 问题不太清楚。用一般的想法描述更多。
  • if (roleosuser.contains("IMPORTER")) { ... }
  • 你的问题似乎不清楚......从我得到的......你想要列表中的一个值..你需要一个 for 循环,你可以得到“进口商”的价值

标签: java arrays spring-mvc


【解决方案1】:

使用这个

 if(roleosuser.contains("IMPORTER")) {
         System.out.println("found");
         // do whatever you want
     }

如果你想知道索引可以使用这个

roleosuser.indexOf("IMPORTER")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 2016-04-04
    • 1970-01-01
    • 2012-05-03
    • 2019-02-21
    • 2011-06-09
    • 1970-01-01
    相关资源
    最近更新 更多