Java selecting words from a string

后端 未结 3 1423
余生分开走
余生分开走 2020-12-19 16:01

HI Everyone. I\'m sorry for this embarrassingly newbie question but I cannot seem to figure out the command to do it. I\'m okay with python and had a script in jython that I

相关标签:
3条回答
  • 2020-12-19 16:04

    Please take a look at String.split method

    0 讨论(0)
  • 2020-12-19 16:17

    I think you are looking for String.split.

    String s = "Java is really cool";
    String words[] = s.split(" ");
    String firstTwo = words[0] + "  " + words[1]; // first two words
    String lastTwo = words[words.length - 2] + " "
            + words[words.length - 1]; // last two words
    
    0 讨论(0)
  • 2020-12-19 16:26
    String foo = "java is really cool";
    String bar[] = foo.split(" ");
    

    this will separate all of the words into an array.

    0 讨论(0)
提交回复
热议问题