Solved

LinkedList data structure ... also synchronized?

Posted on 2006-06-13
7
340 Views
Last Modified: 2010-03-31
I need to implement a linkedlist type of datastructure, where nodes are linearly ordered, nodes are inserted and removed at various positions in the list.

I began experimenting with java's LinkedList class, but it provides no method to insert a node into a list. So do I need to create a new class from scratch or can I somehow append the LinkedList class?

Am I better off implementing my own data structure?

Also there is an example of implemented linked list here:
http://examples.oreilly.com/jenut/LinkedList.java
but I don't quite understand the importance of synchronizing, can anyone give an example as to when its necessary?

Also does implementing the linkable interface do anything for the synchronization?

0
Comment
Question by:polkadot
  • 6
7 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 16896121
If only one thread manipulates the list synchronisation is not necessary.
Otherwise, you need a Vector or must do all the synchronising yourself.

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16896128
... the latter means that all methods that may access the linked list have the keyword   synchronised.


This synchronisation costs overhead!!

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16896149
use methods like  .add(int index, E element) to add a node at a position.

;JOOP!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
ID: 16896165
Find all other methods you need at http://java.sun.com/j2se/1.4.2/docs/api/java/util/LinkedList.html

;JOOP!
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16900704
>> but it provides no method to insert a node into a list.

? Meaning inserting between a list?

0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16900877
I think he means at random position.

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 16917942
:<)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now