+ 1
Can anyone tell me that, In java how to return int array with square brackets like for python we use list then how to do java
9 Answers
+ 3
Put the array as the return type of the function, like this. It can be also not static, if you instantiate your class.
static int[] getNumbers()
https://code.sololearn.com/cwFCAiLQ82W5/?ref=app
+ 3
1. Java is not Python, Java code is typically more verbose. Generally, trying to compress a program to one line, and breaking the usual style conventions, is a bad idea.
2. The problem statement on Leetcode is sort of pseudocode. Array syntax in Java is different. You can find lots of ways to declare Java array, here:
https://stackoverflow.com/questions/1200621/how-do-i-declare-and-initialize-an-array-in-java
+ 2
You can try this way :
int[] result = { 1,2 } ;
System.out.print(java.util.Arrays.toString( result ));
+ 2
Thank you Jayakrishna🇮🇳 I got output thank you
+ 1
Thank you so much brother
+ 1
You're welcome.. Onkar Ambuse
0
Actually I'm saying like this
[1, 2,3,4]
How to return this from function in java
With square brackets and on one line
0
I have facing this for the following
Leetcode problem
https://leetcode.com/problems/two-sum
0
Ok thank you🙏