int a
defines a primitive int.
int[] a = new int[1];
defines an array that has space to hold 1 int.
They are two very different things. The primitive has no methods/properites on it, but an array has properties on it (length), and methods (specifically its on clone method, and all the methods of Object).
Arrays are a bit of a weird beast. They are defined in the JLS.
In practice, it would make sense to do this when you need to interact with an API that takes an array and operates on the results. It is perfectly valid to pass in a reference to an array with 0, 1, or n properties. There are probably other valid reasons to define an array with 1 element.
I can’t think of any use cases where you would want to define an array with one element, just to bypass the array and get the element.
Related Posts:
- How do I generate random integers within a specific range in Java?
- How do I generate random integers within a specific range in Java?
- How can I properly compare two Integers in Java?
- How to check whether a int is not null or empty?
- Declaring an unsigned int in Java
- Exception in thread “main” java.lang.NumberFormatException: For input string: “S”
- int cannot be converted to string?
- How can I convert integer into float in Java?
- How to implement infinity in Java?
- Converting String Array to an Integer Array
- How to check if the value is integer in java?
- Converting a string to an integer on Android
- Convert an integer to an array of digits
- How can I check if a value is of type Integer?
- “Integer number too large” error message for 600851475143
- Cannot invoke toString() on the primitive type int
- Why int[] a = new int[1] instead of just int a?
- Why cannot cast Integer to String in java?
- Is there a way to convert all comments into javadoc comments? [Eclipse/Java]
- Reverse a string in Java
- “Char cannot be dereferenced” error
- Explanation on Integer.MAX_VALUE and Integer.MIN_VALUE to find min and max value in an array
- How to check if a String contains another String in a case insensitive manner in Java?
- Failed to write core dump. minidumps are not enabled by default on client version of windows
- Non-static variable cannot be referenced from a static context
- SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”
- “Missing return statement” within if / for / while
- How to convert byte array to string and vice versa?
- good example of Javadoc
- How do popBackStack() and replace() operations differ?
- Can’t find mysqladmin on Mac OSX 10.6.8
- What is an AssertionError? In which case should I throw it from my own code?
- How to write a Unit Test?
- Best way to Format a Double value to 2 Decimal places
- Collision resolution in Java HashMap
- “Content is not allowed in prolog” when parsing perfectly valid XML on GAE
- Java Undefined Object
- Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
- How to convert an ArrayList containing Integers to primitive int array?
- Left Hand Side of an Assignment must be a Variable CharAt
- Compiling a java program into an executable
- Java Installation Not Completed / Unable to install Java
- What does ‘SSSXXX’ mean in a java simple date format object?
- Server Tomcat v9.0 Server at localhost failed to start
- Getting java.net.SocketTimeoutException: Connection timed out in android
- What is Java String interning?
- How to set or change the default Java (JDK) version on macOS?
- How can I create an array of linked lists in java?
- What’s the difference between session.persist() and session.save() in Hibernate?
- This view is not constrained
- Enhanced FOR loops in C++
- How can I create an Array of ArrayLists?
- Create a List of primitive int?
- Compiling error: Return type for the method is missing
- How can I fix ‘android.os.NetworkOnMainThreadException’?
- Eclipse does not start when I run the exe?
- How to print to the console in Android Studio?
- java.lang.NumberFormatException: null i
- How do you #include files in java?
- How to use Java in Visual Studio 2017
- List of Arrays in Java
- Extending from two classes
- Web server failed to start. Port 8080 was already in use. Spring Boot microserviceWeb server failed to start. Port 8080 was already in use. Spring Boot microservice
- Could not resolve placeholder in string value
- What is causing this Java “Cannot find symbol” error?
- What does equals(Object obj) do?
- How do I make the method return type generic?
- keytool error bash: keytool: command not found
- Java Error: The constructor is undefined
- Java Embedding Into HTML
- Why it is mandatory to use “throws IOException”
- Terminating a Java Program
- How to add an image to a JPanel?
- How to create JSON Object using String?
- How to repaint a JPanel after have drawn on it?
- Java better way to delete file if exists
- How to send HTTP request in java? [duplicate]
- Best way to represent a fraction in Java?
- java IO Exception: Stream Closed
- Can a normal Class implement multiple interfaces?
- What kind of Java type is “[B”?
- Hibernate – Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
- Node cannot be resolved to a type
- E/AndroidRuntime﹕ FATAL EXCEPTION: main
- Big Oh for (n log n)
- How to programmatically close a JFrame
- Playing .mp3 and .wav in Java?
- Difference between jar and war in Java
- Adding image to JFrame
- Java Fraction Calculator
- How to convert a date to milliseconds
- Eclipse IDE – Error: Build path specifies execution environment Java SE 1.7
- What is the difference between “Double” and “double” in Java?
- How to draw a circle with given X and Y coordinates as the middle spot of the circle?
- In Java, how do I parse XML as a String instead of a file?
- Java Returning method which returns arraylist?
- String cannot be resolved to a type – Java RAD
- IntelliJ IDEA “The selected directory is not a valid home for JDK”
- Simple timeout in java
- Eclipse message saying List cannot be resolved to a type