0

Hello I have an array list that consists of numbers but are strings.

Like this: ["1.1",1.2]. The problem is that I am running into that I am using a for function to split an item of the array list into a string array.

For example if I have array list: ["1.1","1.2"] I would

String[] string_array= array_list.get(0).split("\\.");

That should be working fine, but the problem that I am facing is that it would create a weird string array like [Ljava.lang.String;@ccac396 .

I am not really sure what causes this problem as I used split and array string before and none of this happened.

Note: I am splitting on . ,but since . is a regex I have to use \\. which should split on ..

Here is the part of the code that is causing the problem:

for (int i = 0; i < array_list.size(); i++) {
        String[] splitted_on_for_for_reverse;
        splitted_on_for_for_reverse = array_list.get(i).split("\\.");
        array_list.remove(i);
        String string_to_add = splitted_on_for_for_reverse[1].concat(".").concat(splitted_on_for_for_reverse[0]);
        array_list.add(string_to_add);
    }

I know the problem is not happening from the array list as I have tested it with logs and its fine. the problem is with the string array but I dont know what to do. Any help is appreciated and thanks in advance

5
  • 3
    [Ljava.lang.String;@ccac396 I think you are logging the srray. That is not the way to see it's content. Check it in debugger Commented Jul 30, 2019 at 8:16
  • 1
    String[] string_array= array_list.get(0).split("\."); this does not return a "weird" string array. Maybe you are trying to print it in a weird way. Commented Jul 30, 2019 at 8:16
  • 2
    String.split method return an array. of the split items. Also do not remove the items while you iterate them. Commented Jul 30, 2019 at 8:17
  • 2
    Ok thanks guys it turns it I was logging the array string instead of logging each time of the array separate. Silly Mistake. Thanks everyone Commented Jul 30, 2019 at 8:27
  • 1
    hey guys can you post your comment as an answer so I can mark it as an answer Commented Aug 3, 2019 at 7:32

2 Answers 2

1

[Ljava.lang.String;@ccac396 is not a the string itself, but its location or the location of the string array, respectively. I think you are you printing the whole String[] array, which results in the weird output. Java uses its default toString() method, which often just returns the objects position/reference.

Try to iterate over this array and print each String separately.

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

1 Comment

Thank you for your answer and in fact this is what I were doing. I accepted your answer. Thanks again :)
1

To print a string array you must use

Arrays.toString(string_array);

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.