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

  • Home
  • SEARCH
  • 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 6953995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:32:56+00:00 2026-05-27T14:32:56+00:00

I have an XML array that I access to pull a random question from.

  • 0

I have an XML array that I access to pull a random question from. How would I go about making sure there is no duplicates pulled? My current code follows.

    private void getQuestion() {
    // TODO Auto-generated method stub

    res = getResources();
    qString = res.getStringArray(R.array.questions);

    rQuestion = qString[rgenerator.nextInt(qString.length)];

    tokens = new StringTokenizer(rQuestion, ":");
    wordCount = tokens.countTokens();
    sep = new String[wordCount];
    wArray = 0;
    while (tokens.hasMoreTokens()) {
        sep[wArray] = tokens.nextToken();
        wArray++;
    }

}

Any help would be 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-05-27T14:32:57+00:00Added an answer on May 27, 2026 at 2:32 pm

    I figured it out. I switched it to

    private void getQuestion() {
        res = getResources();
        qString = res.getStringArray(R.array.questions);
        arrayLength = qString.length;
        qTotal = arrayLength;
    
    }
    
    private void getRandom() {
        rnd = rgenerator.nextInt(arrayLength);
        rQuestion = qString[rnd];
        qString[rnd] = "used";
        seperate();
    
    }
    
    private void seperate() {
        if (rQuestion != "used") {
            tokens = new StringTokenizer(rQuestion, ":");
            wordCount = tokens.countTokens();
            sep = new String[wordCount];
            wArray = 0;
            while (tokens.hasMoreTokens()) {
                sep[wArray] = tokens.nextToken();
                wArray++;
            }
            qNumber++;
        } else {
            if (qNumber < qTotal) {
                getRandom();
            } else {
                startActivity(new Intent("com.example.END"));
            }
        }
    
    }
    

    It gets the array from resources, then pulls a random question from the array. It then sets that one to “used” and splits it. It also checks to see if the pulled question is “used, and if it is, it pulls another question. It also goes to the end game activity if all questions are “used”

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

Sidebar

Related Questions

I have an array in an xml file that i'm trying to access, however
I have an array that is created dynamic from an xml document looking something
I have stored data in an array from XML Parsing. In the array I
I have the following XML array: [link]=> array(2) { [0]=> object(SimpleXMLElement)#311 (1) { [@attributes]=>
I have XML files in a directory that I wish to get over to
I have XML that looks something like this: <Root xmlns=http://widgetspecA.com/ns> ...any... <WidgetBox> <A/> <B/>
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have an .xml file that is going to be shipped within my app.
I have a simple XML structure like, that when parse with simplexml_load_string generates this:

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.