r/javahelp • • 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

3 comments sorted by

View all comments

5

u/desrtfx Out of Coffee error - System halted Dec 08 '20
  1. code formatting - you have been called out on that previously.

  2. Had you formatted and properly indented your code, you would see that the return arrstr is outside the method.

  3. Pay attention to details. Your code would not even compile. public not Public, return not Return, 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.