D
D
DR_Demons2014-10-26 23:59:58
Java
DR_Demons, 2014-10-26 23:59:58

How to return a value from a java method?

Good day! Studying java stumbled on banality, how to get the value of s?

public String[] delSpace(String[] mas) {
//    	String[] s;
    	for (final String seq : mas) {
    		String[] s = getDelSpace(seq);
    	}
    	
    return s;
    
  }

in this case, eclipse suggests creating a local variable, when you create it, it suggests renaming s.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Copperfield, 2014-10-27
@DR_Demons

This is how what you want to do should look like.

public String[] delSpace(String[] mas) {
    	String[] s = new String[mas.length];
        for(int i = 0; i < mas.length; i++){
            s[i] = getDelSpase(mas[i]);
        }
        return s;
    }

Outside the loop, initialize an array of strings the size of the mas argument. Loop through the array and do whatever you want. Return.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question