r/javahelp • u/[deleted] • Dec 08 '20
String array help
So for assignment for my java class, I have to make a program that manipulates strings. One part of the program i have a file where I read in a list of string. Then I have a method which splits the string which is separated by "/". Then that method puts it into a array[]. So when I tried to return the array it kept giving me type mismatch error.
Code:
Public static String[ ] breaksupstr(String n){ String[] arrstr=n.split("/", 3); } Return arrstr; }
Error return invalid type.
0
Upvotes
5
u/desrtfx Out of Coffee error - System halted Dec 08 '20
code formatting - you have been called out on that previously.
Had you formatted and properly indented your code, you would see that the
return arrstris outside the method.Pay attention to details. Your code would not even compile.
publicnotPublic,returnnotReturn, etc. - Programmers need to learn to pay attention to the tiniest details because a single misplaced character (as in your case) can cause huge problems.