Create methods that accept arrays as parameters and return arrays as return values. - Java Language Basics

Java examples for Language Basics:Array

Introduction

Here's a static method that creates and returns a String array with the names of the days of the week:

Demo Code

public class Main {

  public static void main(String[] args) {

    String[] days = getDaysOfWeek();
    printStringArray(days);//from   ww w  . j ava2s  .c  o m
  }

  public static String[] getDaysOfWeek() {
    String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
        "Friday", "Saturday" };
    return days;
  }

  public static void printStringArray(String[] strings) {
    for (String s : strings)
      System.out.println(s);
  }
}

Related Tutorials