0

Why do I get a weird output for this code?

public class Program { public static void main(String[] args) { String[ ] myNames = { "A", "B", "C", "D"}; System.out.println(myNames); } }

26th Sep 2018, 1:25 AM
Technical Guruji
Technical Guruji - avatar
1 Answer
+ 1
It's the data structure you chose. If you add the index, it may show correct answer, but the full data (myNames) isn't what you see. Look this to get a better overview: public class Program { public static void main(String[] args) { String[ ] myNames = { "A", "B", "C", "D"}; String str = String.join("", myNames); System.out.println(str); } }
26th Sep 2018, 2:58 AM
Alexander Santos
Alexander Santos - avatar