Text manipulation basic Java Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Text manipulation basic Java without wasting too much if your time.

The question is published on by Tutorial Guruji team.

So I have a text document in a format like this:

80  Egypt           12  1   0   0   13  0
81  Qatar           7   4   1   1   13  0

I would like to read it in line by line and store the name of the country along with the highest number (which will always be the 5th number.

However, when I do the following then I am getting an array out of bounds error because it isn’t splitting the line up at all.

     String st;
     while ((st = br.readLine()) != null) {

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

     System.out.println(temp[1]);

     }

edit: reason is that they are tabs not spaces and can be fixed with:

st.replace("t", "");

Answer

It may be the case the file has tabs instead of spaces

We are here to answer your question about Text manipulation basic Java - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji