One returns Double; the other, double.
The differences between primitive Java types and their wrapper counterparts are discussed, for example, here.
Answer from NPE on Stack Overflow"double[] myList = new double[10]" -- super easy noob question. why is double necessary to be stated twice?
Double[] instead of double[] variable declarator
Double array initialization in Java - Stack Overflow
List<Double> vs double[]
Ohhhhh yes, there are differences. You are dealing with Lists vs Arrays. They are two different beasts. The most important difference (in my mind) is that an array has a set size, whereas a list can grow or shrink to fit the elements it contains. However, there are a lot of other significant differences, so I would encourage you to just Google ArrayList vs Array and read an article or two about it. I'm on my phone so I can't write much of an extensive answer myself, and most resources you'll find in a Google search will do a better job than I would anyways.
As for the Double vs double usage, a List must have objects as elements, whereas arrays can contain objects or primitives (e.g integers and doubles). Double is essentially an object version of the primitive double (really it's a wrapper class, but that's not something you should worry about too much right now). Hope that helps clear it up a bit...
More on reddit.comVideos
As in, the way Java works, why was it designed this way.. I understand double[] myList but why is it necessary to state double... same thing with like... Scanner input = new Scanner(System.in)
it just feels... redundant.. but im at such a low level, my curiosity got to me. whats the utility of this?
can you show me a short line of code that shows the deeper complexity of declaring a new instance.
id imagine its just a syntax thing built into java/previous languages.. but i guess from my experience with higher level languages seem to have really simplified the type of statement above
This is array initializer syntax, and it can only be used on the right-hand-side when declaring a variable of array type. Example:
int[] x = {1,2,3,4};
String[] y = {"a","b","c"};
If you're not on the RHS of a variable declaration, use an array constructor instead:
int[] x;
x = new int[]{1,2,3,4};
String[] y;
y = new String[]{"a","b","c"};
These declarations have the exact same effect: a new array is allocated and constructed with the specified contents.
In your case, it might actually be clearer (less repetitive, but a bit less concise) to specify the table programmatically:
double[][] m = new double[4][4];
for(int i=0; i<4; i++) {
for(int j=0; j<4; j++) {
m[i][j] = i*j;
}
}
You can initialize an array by writing actual values it holds in curly braces on the right hand side like:
String[] strArr = { "one", "two", "three"};
int[] numArr = { 1, 2, 3};
In the same manner two-dimensional array or array-of-arrays holds an array as a value, so:
String strArrayOfArrays = { {"a", "b", "c"}, {"one", "two", "three"} };
Your example shows exactly that
double m[][] = {
{0*0,1*0,2*0,3*0},
{0*1,1*1,2*1,3*1},
{0*2,1*2,2*2,3*2},
{0*3,1*3,2*3,3*3}
};
But also the multiplication of number will also be performed and its the same as:
double m[][] = { {0, 0, 0, 0}, {0, 1, 2, 3}, {0, 2, 4, 6}, {0, 3, 6, 9} };
What are the major differences between the two? I know Double and double are different, so I guess my question is more on the collections. Is there anything important to consider when working with one collection vs the other?
I have an example: https://pastebin.com/2qM9vBsu
The goal of the method is to add arrays/lists similar to vector addition. IE, sumList([3, 6], [2, 1]) would return [5,7].
I can already tell that there are some differences with, I realize working with List<Double> I'll have access to class Double methods whereas double is a primitive. Is there anything about the collection types that I should know?
Ohhhhh yes, there are differences. You are dealing with Lists vs Arrays. They are two different beasts. The most important difference (in my mind) is that an array has a set size, whereas a list can grow or shrink to fit the elements it contains. However, there are a lot of other significant differences, so I would encourage you to just Google ArrayList vs Array and read an article or two about it. I'm on my phone so I can't write much of an extensive answer myself, and most resources you'll find in a Google search will do a better job than I would anyways.
As for the Double vs double usage, a List must have objects as elements, whereas arrays can contain objects or primitives (e.g integers and doubles). Double is essentially an object version of the primitive double (really it's a wrapper class, but that's not something you should worry about too much right now). Hope that helps clear it up a bit...
Their biggest difference is that arrays have a fixed size that you must define when you create the array while Lists can (seemingly) hold an unlimited number of objects.
ArrayLists actually use arrays under the hood. ArrayLists are simply more convenient to use in many situation because they provide us a higher level of abstraction. Rather than saying "I want to have a collection of at most 100 users" we can simply say "I want to have a collection of users" and the class will worry about the fact that we don't have unlimited memory.