【问题标题】:java - compare two string to list and create new listjava - 比较两个字符串到列表并创建新列表
【发布时间】:2017-07-17 11:42:51
【问题描述】:

如果列表包含超过 100 个元素,例如:

list.add(str);

我们从循环中获取 str 的地方。

如果我们还有另外两个这样的字符串:

String strStart;
String strEnd;

现在我们要将两个字符串与所有列表元素进行比较。 例如: 如果列表包含“Afg”、“Alb”、“Ban”...

strStart = "Alb";
strEnd = "Ger";

我们想用

创建新列表
only this two string
and the string between theme.

【问题讨论】:

  • 你的问题是什么?您在实施时遇到了什么问题?
  • 我认为你希望别人解决你的“问题”而不用考虑它。首先,您是否尝试过在循环中使用字符串比较或其他方式?
  • 问一个问题这里没有问题。

标签: java string list compare


【解决方案1】:
public static void main(String[] args) {
    List<String> list = Arrays.asList("abc","def","ghi","jkl","mno","pqr","stw");
    String strStart = "def";
    String strEnd   = "mno";
    List<String> subList = list.subList(list.indexOf(strStart), list.indexOf(strEnd)+1);
    System.out.println(subList);
}

【讨论】:

  • 嗨@Eritrean,这是我想要的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-07
  • 1970-01-01
  • 2019-04-08
  • 1970-01-01
  • 1970-01-01
  • 2021-10-03
相关资源
最近更新 更多