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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:59:04+00:00 2026-06-03T20:59:04+00:00

how to get string variables from a whole string in java. if i am

  • 0

how to get string variables from a whole string in java.

if i am given a string which is created this way:

String s = "Name:" + name + "Age:" + age + "Sex:" + sex;

how can i get name, age, sex from this String s.

I cannot use getWord(position) or something like that because i dont know how many words will be there in name, and how the age is represented
age = “22 years” or age = “22 years 5 months”.

  • 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-03T20:59:05+00:00Added an answer on June 3, 2026 at 8:59 pm

    I suggest you to have the Name, Age and Sex splitted by "," character.

    It means:

    String s = "Name:" + name + ",Age:" + age + ",Sex:" + sex;
    

    Then you can split the string s by “,”

    String properties = s.split(",");
    

    Then from properties variable, you can split by ":" to take the Property name and the value of that property.

    Is that clear?

    I’m adding more code to support another ways as you wanted:

    String name = "Thuan";
    String age = "27";
    String sex = "male";
    String s = "Name:" + name + "Age:" + age + "Sex:" + sex;
    
    int nameIndex = s.indexOf("Name:");
    int ageIndex = s.indexOf("Age:");
    int sexIndex = s.indexOf("Sex:");
    
    String theName = s.substring(nameIndex + "Name:".length(), ageIndex);
    String theAge = s.substring(ageIndex + "Age:".length(), sexIndex);
    String theSex = s.substring(sexIndex + "Sex:".length(), s.length());
    
    System.out.println(theName);
    System.out.println(theAge);
    System.out.println(theSex);
    

    Please be note that this is just example show you the logic, you need to refactor yourself.

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

Sidebar

Related Questions

My Java code must get string HH:MM from console and needs to operate with
I try to get string from this url: http://autoc.finance.yahoo.com/autoc?query=google&callback=YAHOO.Finance.SymbolSuggest.ssCallback When I look at this
I created a Java Servlet that get query result from mySQL database and print
I can't get my head around how formatting a datetime variable inside a string
I need to get string array or list with ajax and Action, this is
I get a String data from Cursor, but I don't know how to convert
I get json string from server. Then I parser it using SBJSON library. But
How can i get the string within a parenthesis with a custom function? e.x.
I am trying to access STATIC Variables from one java class to another but
I am getting this error when i use a string array java.lang.NullPointerException The code

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.