T
Taria
Hello all,
I hope I"m posting this in the right place. Java is somewhat new to
me, and I'm not really comfortable with handling objects, hence my
confusion.
I'm trying to create an array of size N with objects that will be
linked lists in the array (essentially doing a bucket sort and the
requirement is to be able to create linked lists in a bucket in the
event of a collision.)
In my brilliance, I figured I could put objects that were linked lists
in the array with the cell of the array pointing to the head of each
linked list. (just humor me, I'm trying to initialize an array with
an object to start, never mind the sorting part for now.)
This is the code I tried:
String [] bucket; // this is my array to hold the objects
for (int i = 0;i< N;i++){
bucket = new LinkedList(); //linked list is my object
}
The error I get is non static variable cannot be referenced from a
static context.
I understand that there is a conflict of a primitive variable
reference to an object reference, but is it referring to the bucket
array as a static? Does this mean I need to declare the array to be
an object, too? :x
I pulled this code off someone else's msg that said this would work
and I have no doubt of that, but I don't understand it.
public class AnyObj {
public Object[] someMethod( )
{
AnyObj arrayOfObj[] = new AnyObj[5];
arrayOfObj[0] = new AnyObj();
arrayOfObj[4] = new AnyObj();
return arrayOfObj;
}
My question here is this appears to be an array of AnyObj, in my case,
if I were to substitute my array name, then each cell would become a
part of the Linked list object? (sorry if i'm not making sense, i'm
delirious, it's late, i'm tired and i've been working on this for a
long time.) If my linked list object had a head and node, wouldn't
the array have that too if I declared it to be an object linked list?
Confusion couldn't be finer right now.
And finally, am I approaching this problem the right way? How
plausible is an array of linked lists? I mean, is Java capable?
Any thoughts or hints are appreciated.
-m
if only they made compilers newbie friendly.
I hope I"m posting this in the right place. Java is somewhat new to
me, and I'm not really comfortable with handling objects, hence my
confusion.
I'm trying to create an array of size N with objects that will be
linked lists in the array (essentially doing a bucket sort and the
requirement is to be able to create linked lists in a bucket in the
event of a collision.)
In my brilliance, I figured I could put objects that were linked lists
in the array with the cell of the array pointing to the head of each
linked list. (just humor me, I'm trying to initialize an array with
an object to start, never mind the sorting part for now.)
This is the code I tried:
String [] bucket; // this is my array to hold the objects
for (int i = 0;i< N;i++){
bucket = new LinkedList(); //linked list is my object
}
The error I get is non static variable cannot be referenced from a
static context.
I understand that there is a conflict of a primitive variable
reference to an object reference, but is it referring to the bucket
array as a static? Does this mean I need to declare the array to be
an object, too? :x
I pulled this code off someone else's msg that said this would work
and I have no doubt of that, but I don't understand it.
public class AnyObj {
public Object[] someMethod( )
{
AnyObj arrayOfObj[] = new AnyObj[5];
arrayOfObj[0] = new AnyObj();
arrayOfObj[4] = new AnyObj();
return arrayOfObj;
}
My question here is this appears to be an array of AnyObj, in my case,
if I were to substitute my array name, then each cell would become a
part of the Linked list object? (sorry if i'm not making sense, i'm
delirious, it's late, i'm tired and i've been working on this for a
long time.) If my linked list object had a head and node, wouldn't
the array have that too if I declared it to be an object linked list?
Confusion couldn't be finer right now.
And finally, am I approaching this problem the right way? How
plausible is an array of linked lists? I mean, is Java capable?
Any thoughts or hints are appreciated.
-m
if only they made compilers newbie friendly.