[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

conversion of string to string array in java

Hi can any one explain to me how to convert this string to string array.
String record ="123,srini masi,229 WEST LOOP 121"
this my String i am getting this from database every time string value will be changed it is a dynamic value
i want to convert this String into below format.
String[] records = { "123", "srini masi", "229 WEST LOOP 121"}
0
srikotesh
Asked:
srikotesh
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
contactkarthiCommented:
String[] records = record .split(",");
0
 
srikoteshAuthor Commented:
if suppose my string will be like this
String record = "000123814    JOHN ADAM     229 WEST LOOP ";
now how can i split  if i go with space
String[] records = record .split(" ");
 i am getting wrong data because john adam i need to get as one and 229 WEST LOOP this value i have to get as one string.

can u suggest in this scenario
0
 
contactkarthiCommented:
how are you getting the string in the first place? is it a field in database or a combination of multiple fields?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
srikoteshAuthor Commented:
output is the column in database
that contains this value  000123814    JOHN ADAM     229 WEST LOOP
that column datatype is varchar(2000)
i need to get the value from that column assign to strignarray
0
 
contactkarthiCommented:
String[] records = record .split("\\s{2,}");

it will split if there are more than 1 space
0
 
CEHJCommented:
0
 
Jeffrey Dake Senior Director of TechnologyCommented:
I would take a step back and look at how you are getting this string.  If you are using a result set to load the data from the database you should already be able to load each column into their own field.  

http://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html
0
 
srikoteshAuthor Commented:
thanks karthi for ur help
now it is working fine. i am able to insert values into csv file.
thanks cehj for ur suggestion that way also we can do but we need to pass the latest idvalue  that is inserted in db,based on idvalue we can fetch output  column from the table.
0
 
CEHJCommented:
:)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now