What is the array initialization syntax when not in a declaration?

0 votes

Please help.

Jul 13, 2018 in Java by scarlett
• 1,280 points
14 views

1 answer to this question.

0 votes

Probably you'd have to ask the Java designers.

You can write this:

AClass[] arr;
...
arr = new AClass[]{obj1, obj2};
answered Jul 13, 2018 by Akrati
• 3,150 points

Related Questions In Java

0 votes
2 answers

What is the syntax to initialize an array?

Rather than learning un-Official websites learn from ...READ MORE

answered Aug 2, 2018 in Java by samarth295
• 2,190 points
39 views
0 votes
1 answer

How can I invoke a method when the method name is in the form of a given string?

I tried doing it this way - java.lang.reflect.Method ...READ MORE

answered Apr 27, 2018 in Java by developer_1
• 3,280 points
42 views
0 votes
1 answer

What is the simplest way to read JSON from a URL in java

Read json from url use url.openStream() and read contents ...READ MORE

answered Jun 13, 2018 in Java by samarth295
• 2,190 points
149 views
0 votes
1 answer

What is the easiest way to iterate through the characters of a string in Java?

The below code seems the easiest to ...READ MORE

answered Jul 13, 2018 in Java by scarlett
• 1,280 points
40 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
201 views
0 votes
2 answers

One line initialization of an ArrayList object in Java

In Java 8 or earlier: List<String> string = ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,190 points
109 views
0 votes
2 answers

How to convert an array to arraylist?

In Java 9 you can use: List<String> list= List.of("Hello", "World", ...READ MORE

answered Aug 1, 2018 in Java by samarth295
• 2,190 points
33 views
0 votes
3 answers

How to sort an array in java?

import java.util.Arrays; public class Sort { ...READ MORE

answered Aug 24, 2018 in Java by parth295
• 4,600 points
49 views
0 votes
1 answer

What is the use of @Override annotation in Java ? When do we use it ?

I think it is most useful as ...READ MORE

answered May 4, 2018 in Java by Akrati
• 3,150 points
70 views
0 votes
1 answer

What is the difference between Set and List in java?

List is an ordered sequence of elements. ...READ MORE

answered Apr 26, 2018 in Java by Akrati
• 3,150 points
64 views