How to split a sentence into two parts

后端 未结 5 1307
半阙折子戏
半阙折子戏 2021-01-21 20:29

How to split a sentence into two parts in JAVA? If there is the following

String sentence = \"I love Java <=> I love Python\"

How can I

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-21 21:00

    You can also split with StringTokenizer.

    The code for splitting the strings based upon delimiter is below:

    StringTokenizer stringTokenizer = new StringTokenizer(sentence,"<=>");
            while(stringTokenizer.hasMoreTokens()) {
                System.out.println(stringTokenizer.nextToken());
            }
    

    I hope this helps

    Thanks

提交回复
热议问题