0
private static void readSplitPrint(String path) {
    try {
        for (String line : Files.readAllLines(Paths.get(path))) {
            for (String word : line.split("/t")) {
                System.out.println(path + " : " + word);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

I have a default code for my homework. I need to use it and it works for reading a text file to complete my project. But I have some trouble about this topic. I can't convert a string object which is called 'word' to any string[] object. I'm begginer and I don't know how to do it with using Array easily. So I need to convert and hold these words and -of course it is possible- keep it any String[] or String[][] object to use as "x[0][0]" or "x[2][3]" matrix type. Can anyone help to me?

1 Answer 1

1

You do not need to "convert" any kind of object in order to "turn it" into an array of object. An array is a container; and you just instruct the program to stuff that object into the container.

String foo = "bar";
String[] arrayOfStringsWithLengthOne = new String[1];
arrayOfStringsWithLengthOne[0] = foo;

is all that you need.

But keep in mind: stackoverflow is not a programming school. This is something where you should not look to over people to explain it to you. You should turn to books and tutorials and just read the stuff. You can't came here for every little problem that you will encounter when learning a programming language. And a hint: as long as you have trouble understanding such very basic things about arrays; better forget about the two-dimenensional ones for the moment. Learn the basics; one by one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.