Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

When the user opens it, a file will be opened in JTabbedPane. I did the following to save the files opened:

HashMap<String, Tab> hash = new HashMap<String, Tab>();

Where Tab will receive the values, such as: File file, JTextArea container, JTabbedPane tab.

I have a class called Tab:

public Tab(File file, JTextArea container, JTabbedPane tab)
{
    this.file = file;
    this.container = container;
    this.tab = tab;
    tab.add(file.getName(), container);
    readFile();
}

Now, in this SaveFile class, I need to get the Tab values stored in the HashMap, Can somebody tell me the syntax to do this?

1 Answer

0 votes
by (13.1k points)

To process all values:

hash.values().forEach(tab -> /*something to do with the tab */);

To process all entries:

hash.forEach((key, tab) -> /* something to do with the keys and tab*/);

This works with Java8.

Want to learn Java? check out the java certification

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...