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 7036989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:29:23+00:00 2026-05-28T01:29:23+00:00

Is there a way to retrieve a string from an ArrayList if we know

  • 0

Is there a way to retrieve a string from an ArrayList if we know the index of the string we want to retrieve? for example in this string:

String text2 = "if(AGE_Y>15){\r\n"
                + "x=PROPERTY_LENGTH;\r\n"
                + "}";

The list this string is added to would look like : if, (, AGE_Y, >, 15, ), {, ...

Now if we loop through the list and add each item to a StringBuilder and define the index for each item:

for (int i = 0; i < list.size(); i++)
{
   a=list.get(i);
   strBuilder.append(a); 
   index = strBuilder.length() - a.length();
}

We will know exactly at what index we have the string “PROPERTY_LENGTH” for example.

My question is, how can we retrieve the string “x” from the List? I’m asking because at the line above “x”(or whatever that variable will be named) I want to insert something else in the StringBuilder. Normally we could do something like:

 String previous=list.get(indexOfPropertyLength-2);
 strBuilder.insert(index-previous.length-1,"string to insert");

Is this at all possible?

  • 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-28T01:29:23+00:00Added an answer on May 28, 2026 at 1:29 am

    Firstly you can rewrite your list iteration to work more efficiently:

    for (int i = 0; i < list.size(); i++) {
        a=list.get(i);
        index = strBuilder.length(); // (you don't have to calculate an index)
        strBuilder.append(a); 
    }
    

    To address the title of your question, if you want to simply find a String in a List given an index, you can of course use myList.get(myIntIndex);. However, it seems that you’re asking how to find an index given a String: myList.indexOf(myString) or something of that nature. If you could be a bit clearer, we might be of more help. Are you writing a hybrid assembler or compiler?

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

Sidebar

Related Questions

Is there a simple way to retrieve a filtered list of files from an
Is there a way to retrieve first n elements from a Dictionary in C#?
is there a way to retrieve type T from IEnumerable<T> through reflection? e.g. i
Is there a way to retrieve the auto generated key from a DB query
Is there a way to retrieve path information from a file descriptor or FILE
Is there a way to retrieve wcf binding type and security mode just from
Is there any way to retrieve the address map file for ntdll.dll? I know
is there any way in .Net 2.0 to retrieve a property name from delegate?:
Is there a way to create a new class from a String variable in
If I've used LINQ to retrieve results from the database, is there a way

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.