- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Returning an array in Java
Yes, an array can be returned from a java function. See the example below −
Example
public class Tester { public static void main(String[] args) { int[] array = getData(); for(int i: array) { System.out.println(i); } } public static int[] getData() { int[] dataArray = {1, 2, 3, 4}; return dataArray; } }
Output
1 2 3 4
- Related Articles
- Returning an Array from a Method in Java
- Returning the highest value from an array in JavaScript
- Returning an array containing last n even numbers from input array in JavaScript
- Returning just greater array in JavaScript
- Returning an array with the minimum and maximum elements JavaScript
- Passing and Returning Objects in Java
- Returning the first number that equals its index in an array using JavaScript
- Returning only odd number from array in JavaScript
- Returning the value of (count of positive / sum of negatives) for an array in JavaScript
- Returning array values that are not odd in JavaScript
- Returning reverse array of integers using JavaScript
- Accessing and returning nested array value - JavaScript?
- Returning array of natural numbers between a range in JavaScript
- JavaScript array.includes inside nested array returning false where as searched name is in array
- What is an array in Java?

Advertisements