【问题标题】:Split In Java with condition在 Java 中使用条件拆分
【发布时间】:2021-07-01 05:05:57
【问题描述】:

在java中拆分字符串:- 我尝试使用以下代码,但没有得到预期的 o/p

 String[] SplitString = s.split(" ");
 String s= "Apple not in Vegetable,Object,Item"
 Expected o/p = Apple
 Expected o/p = not in
 Expected o/p = Vegetable,Object,Item

【问题讨论】:

  • 你是按空格分割的,你怎么期望not in作为单个字符串出现?这里有一个空间。
  • 输出应该是 Apple \n 而不是 \n \n Vegetable,Object,Item

标签: java string split


【解决方案1】:

你可以试试这个sn-p

        String[] SplitString = s.split(" ");
        for (String value : SplitString) {
            System.out.println(value);
        }

not in 字符串之间的空格,因此它将分成 notin 字符串。 预期输出:->

Apple
not
in
Vegetable,Object,Item

【讨论】:

  • 是的,你是对的,那我怎样才能得到预期的 O/P?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-03
  • 1970-01-01
  • 1970-01-01
  • 2015-05-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多