Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: help with using Java ArrayList

  1. #1
    Member
    Join Date
    May 2011
    Posts
    61
    My Mood
    Busy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with using Java ArrayList

    I'm learning to build an directed graph data structure using adjacency lists, so I thought I'd use LinkedLists to ensure efficient linked list used and I wanted to use an array of Linked list, but I had trouble so I decided to use ArrayList of LinkedList of type Integer, but compiler complains about generics.

    The problem I have is having a wrapper that adds a new vertex to the current end of a LL (so it's a wrapper for addLast(Elem e) which is really a LinkedList method)

    import java.util.*;
    import java.lang.*;
     
    class Graph//implemented via adjacency lists
    {
    	public Graph(int size)
    	{
    		this.size = size;
    		l = new LinkedList(size);
    	}
     
    	public void add_to_end(Integer i)//problem here...
    	{
    		this.l.add(i);//PROBLEM: this.l is a Linked List data member but compiler complains...
    	}
     
     
    	public void print(){return;}//prints each index (so each adjacent node for a given node)
     
     
    	public void dft(){return;}//Depth-first traversal of current graph
     
     
    	public void bft(){return;}//breadth-first " "
     
     
    	public int get_size(){return this.size;}
     
    	private int size;//number of vertices
    	private ArrayList l;
    }
     
    public class Graphs_runner
    {	
    	public static void main(String[] args)
    	{
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: help with using Java ArrayList

    compiler complains about generics.
    Please post the full text of the error message.

    problem I have is having a wrapper that adds a new vertex to the current end of a LL
    Can you explain what you mean? Are you asking how to write a method?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to use an ArrayList and what is its advantage over array?
    By JavaPF in forum Java SE API Tutorials
    Replies: 4
    Last Post: December 21st, 2011, 04:44 AM
  2. private Map<String, ArrayList> xlist = new HashMap<String, ArrayList>();
    By Scotty in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 21st, 2011, 08:37 AM
  3. Ordering ArrayList by 3 conditions as you add to ArrayList
    By aussiemcgr in forum Collections and Generics
    Replies: 4
    Last Post: July 13th, 2010, 02:08 PM
  4. [SOLVED] Extracting an How to ArrayList from an ArrayList and convert to int??
    By igniteflow in forum Collections and Generics
    Replies: 2
    Last Post: August 16th, 2009, 01:11 PM
  5. How to use an ArrayList and what is its advantage over array?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: May 17th, 2009, 01:12 PM