Java中的split()方法不适用于点(。) [英] The split() method in Java does not work on a dot (.)

查看:234
本文介绍了Java中的split()方法不适用于点(。)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我准备了一个简单的代码段,以便将错误的部分与我的网络应用程序分开。

I have prepared a simple code snippet in order to separate the erroneous portion from my web application.

public class Main {

    public static void main(String[] args) throws IOException {
        System.out.print("\nEnter a string:->");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String temp = br.readLine();

        String words[] = temp.split(".");

        for (int i = 0; i < words.length; i++) {
            System.out.println(words[i] + "\n");
        }
    }
}

我在建筑时测试了它一个Web应用程序JSF。我只是想知道为什么在上面的代码 temp.split(。)不起作用。声明,

I have tested it while building a web application JSF. I just want to know why in the above code temp.split(".") does not work. The statement,

System.out.println(words[i]+"\n"); 

在控制台上没有显示任何内容,表示它没有通过循环。当我将 temp.split()方法的参数更改为其他字符时,它可以正常工作。可能是什么问题?

displays nothing on the console means that it doesn't go through the loop. When I change the argument of the temp.split() method to other characters, It works just fine as usual. What might be the problem?

推荐答案

java.lang.String.split 对正则表达式进行拆分和正常表达式中的表示任何字符。

尝试 temp。拆分(\\。)

这篇关于Java中的split()方法不适用于点(。)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆