Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:52:17+00:00 2026-06-16T00:52:17+00:00

I am new to both Java and Android so hopefully my question will make

  • 0

I am new to both Java and Android so hopefully my question will make sense (I think I know what I am asking!)

I am working my way through an example in a book and I have a query with the following statement:

String[] tags = savedSearches.getAll().keySet().toArray(new String[0]);

Where savedSearches is a SharedPreferences Object.

savedSearches.getAll() returns a Map which allows the call to KeySet() to be made. What I am failing to understand is how the KeySet() call is possible. I am under the impression that if you are going to be using a class/Interface in your code then you need to import it or import a class/Interface which directly or Indirectly extends/implements the object making the call, in this case a reference to a Map.

The example I am working on imports the following:

import java.util.Arrays;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;

I have had a look at the Java and Android API and I can’t see that a Map is implemented in any of the above (unless I have missed it!) so in principle I should not be able to make a call to KeySet(). So how is it possible to make this call to KeySet()?

Hopefully the above will make some sort of sense :/ Any help or pointers in the right direction to help me understand this would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:52:18+00:00Added an answer on June 16, 2026 at 12:52 am

    keySet() is a method that returns a set of all the keys of the Map(public Set<K> keySet ()). So, methods are not to be imported. Though Map is not imported but the return type of getAll() method is Map<String, ?> so it can be directly accessed.

    If you fetch getAll() seperately like,

    Map<String, ?> map = preferences.getAll();
    

    Then you will have Map imported else you can directly access it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

sorry for asking dumb questions, java and Android are both new to me ;)
I'm new to Java and Android development so I decided to make a simple
i'm new to programming in Java and android... Here is my question, again not
I'm very new to both android and java development. I am attempting to build
Firstly, I am new to both android and Java. I have two classes, my
New to both Android development and Java, trying to separate my queries into query
Our team is new to both Android and Java development (originally, we came from
I'm new to both Java and Android development so this might be a stupid
I'm rather new to both Java programming and to Android development, so my learning
Hi im new to both android and java i have php page in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.