Arrays. What am I doing wrong?
Posted: Wed Jul 22, 2020 8:58 am
Could anyone please confirm how I am supposed to use arrays?
I'm just trying to create arrays, adding items (defining a fixed array with all values would be nice instead of adding values seperately)
Then I'd like to use collections.shuffle
then I'd like to just use basic functions like myarray.contains(x) to return a bolean and myarray.get(x) to return an item at a specified index. All pretty simple stuff.
Problem I'm having is first I created my arrays OK but had to include java.util (is this OK?)
But then when comparing any values the whole thing broke and I was getting the array raw type errors.
So I though it might be because I was comparing a mix of int and double so I tried creating an array of double type but found out online arrays dont take double (raw type) but in later versions I could leave it unspecified (<>) and it would work it out itself. But then I got errors with that too.
Heres the sort of thing I'm up to at the moment (without the get() or collections.shuffle() etc:
ArrayList<> CH14list = new ArrayList<>();
for (int i = 1; i <= CH1lengthknob.GetValue(); i++) {
CH14list.add(i);
}
Could anyone please advise or point me to the best docs that show me how I am supposed to be working with arrays so I can do it 'properly'. I am getting so much conflicting advise on the internet and none of it is working.
I am using OpenJDK 14.0.1
Thanks
I'm just trying to create arrays, adding items (defining a fixed array with all values would be nice instead of adding values seperately)
Then I'd like to use collections.shuffle
then I'd like to just use basic functions like myarray.contains(x) to return a bolean and myarray.get(x) to return an item at a specified index. All pretty simple stuff.
Problem I'm having is first I created my arrays OK but had to include java.util (is this OK?)
But then when comparing any values the whole thing broke and I was getting the array raw type errors.
So I though it might be because I was comparing a mix of int and double so I tried creating an array of double type but found out online arrays dont take double (raw type) but in later versions I could leave it unspecified (<>) and it would work it out itself. But then I got errors with that too.
Heres the sort of thing I'm up to at the moment (without the get() or collections.shuffle() etc:
ArrayList<> CH14list = new ArrayList<>();
for (int i = 1; i <= CH1lengthknob.GetValue(); i++) {
CH14list.add(i);
}
Could anyone please advise or point me to the best docs that show me how I am supposed to be working with arrays so I can do it 'properly'. I am getting so much conflicting advise on the internet and none of it is working.
I am using OpenJDK 14.0.1
Thanks