Re: Cannot find symbol java error (newbie question)



On Sat, 29 Sep 2007 02:34:22 -0700, Taria <mchew02@xxxxxxxxxxx> wrote,
quoted or indirectly quoted someone who said :

import java.util.*;
import java.lang.*;

public class myProg{

public static void main(String[] arguments) {
int size = 10; // arbritray size - test number
LinkedList [] bucketArray = new LinkedList[size];

// next try to insert the value into bucket array
//bucketArray[1] = array[0]; incompatible types (my first
attempt to assign a value :p)

Integer four = new Integer(4); //so now four is an object
bucketArray.insert(four,0); //cannot find symbol
} //end of main

class LinkedList{
private Node head;
private int length;

public LinkedList() {
this.head = null;
this.length = 0;
}

public void insert (Object data,int position){
System.out.println ("Node code here\n");

}
}

I have corrected your program as follows.

import java.util.*;
import java.lang.*;

/** shows compiler error message */
public class MyProg
{

public static final int MAX_BUCKETS = 10; // arbitrary size - test
number


public static void main(String[] arguments)
{
// create an array of LinkedLists
LinkedList [] bucketArray = new LinkedList[ MAX_BUCKETS ];

// next insert value into bucket array

// bucketArray uses array[] syntax, the LinkList contents use
method syntax.
Integer four = new Integer(4); //so now four is an object
// need to create an LinkedList to add to the array, not an
Object
LinkedList ll = new LinkedList();
ll.insert ( four, 0 );
// now add the linked list to the array.
bucketArray[0] = ll;

} //end of main
}

/** top level class to implement a LinkedList */

class LinkedList
{
private Node head;
private int length;

public LinkedList()
{
this.head = null;
this.length = 0;
}

public void insert (Object data,int position)
{
System.out.println ("Node code here\n");
}
}

/** SSCCE was missing a node class. We provide a dummy one */
class Node
{
}


You are confused between arrays and Lists. You rarely need both.

You could either have an array of objects or a LinkedList of Objects,
but you normally would not have an array of LinkedLists of Objects.

See http://mindprod.com/jgloss/array.html
http://mindprod.com/jgloss/arraylist.html

LinkedLists in general are rare since they are slower than other sorts
of lists most of the time. The beauty of the List interface is you can
try several list implementations to see which actually works best with
minimal code change.

Normally you would have an ArrayList<Dog> where Dog is some specific
class. It is rare to see a List<Object> any more.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.



Relevant Pages

  • Re: Cannot find symbol java error (newbie question)
    ... but you normally would not have an array of LinkedLists of Objects. ... LinkedLists in general are rare since they are slower than other sorts ... It is rare to see a Listany more. ... create an array of linked lists ...
    (comp.lang.java.programmer)
  • Re: list files in subdirectory trouble!! please look at this snippet
    ... diNext.GetFileswill return an array of files that matches the expression. ... > i am looking at this piece of code that lists numbers of files in a ... public static void Main ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Hash Code Compression
    ... all of the articles looking for new words. ... Although the hash table is currently Big 0. ... fact the hashTable is an array of LinkedLists is so that it handles ... My lists are currently smallish, i was just hoping someone would know a better hash Code function or a better compression method which would make each linked list have 1 element rather than up to 4 elements. ...
    (comp.lang.java.programmer)
  • Re: Hash Code Compression
    ... all of the articles looking for new words. ... Although the hash table is currently Big 0. ... My hash table is made up of an array of n LinkedLists (where n is a ... fact the hashTable is an array of LinkedLists is so that it handles ...
    (comp.lang.java.programmer)
  • Re: Merging Linked Lists
    ... opposed to linked lists? ... Efficiency is my main prioity for this project. ... ArrayLists are generally faster than LinkedLists if you only add/remove ... While it has a little more overhead than HashSet, ...
    (comp.lang.java.programmer)