New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linked Hash Map Example #1355
Open
suranasourabh
wants to merge
1
commit into
TheAlgorithms:master
from
suranasourabh:master
base: master
+35
−0
Open
Linked Hash Map Example #1355
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
@@ -0,0 +1,35 @@ | ||
import java.util.*; | ||
|
||
class Book { | ||
int id; | ||
String name,author,publisher; | ||
int quantity; | ||
public Book(int id, String name, String author, String publisher, int quantity) { | ||
this.id = id; | ||
this.name = name; | ||
this.author = author; | ||
this.publisher = publisher; | ||
this.quantity = quantity; | ||
} | ||
} | ||
public class MapExample { | ||
public static void main(String[] args) { | ||
//Creating map of Books | ||
Map<Integer,Book> map=new LinkedHashMap<Integer,Book>(); | ||
//Creating Books | ||
Book b1=new Book(101,"Let us C","Yashwant Kanetkar","BPB",8); | ||
Book b2=new Book(102,"Data Communications & Networking","Forouzan","Mc Graw Hill",4); | ||
Book b3=new Book(103,"Operating System","Galvin","Wiley",6); | ||
//Adding Books to map | ||
map.put(2,b2); | ||
map.put(1,b1); | ||
map.put(3,b3); | ||
|
||
//Traversing map | ||
for(Map.Entry<Integer, Book> entry:map.entrySet()){ | ||
int key=entry.getKey(); | ||
Book b=entry.getValue(); | ||
System.out.println(key+" Details:"); | ||
System.out.println(b.id+" "+b.name+" "+b.author+" "+b.publisher+" "+b.quantity); | ||
} | ||
} | ||
} |
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
@suranasourabh Kindly provide a description and a sample case for your repository