1

i have this long list of zipcodes here

90019,90036,90016,90005,90010,90018,90020,90004,90048,90035,90211,90006,90038,90008,90089,90062,90007,90028,90034,90212,90232,90231,90233,90057,90209,90213,90070,90029,90069,90015,90056,90037,90017,90067,90043,90046,90026,90071,90014,90230,90064,90099,90302,90189,90011,90030,90050,90051,90052,90053,90054,90055,90060,90072,90074,90075,90076,90078,90080,90081,90082,90083,90086,90087,90088,90093,90024,90009,90013,90068,90090,90079,90012,90210,90021,90025,90306,90307,90308,90309,90310,90312,90311,90095,90305,91608,90027,90084,90066,90301,90073,90094,90047,91522,91604,90039,90003,90044,91602,90031,91204,91523,90033,90295,90001,90045,90077,91521,90065,90096,90404,90292,90405,90303,90058,90294,90304,90291,91209,91221,91222,91224,91225,91226,91210,91205,90023,91203,91601,91393,91506,91423,90063,90002,90403,90255,91607,91603,91609,91610,91611,91612,91614,91615,91616,91617,91618,90406,90407,90408,90409,90410,90411,90049,91201,91505,91502,90401,90251,90296,90293,91503,91507,91508,91510,91526,90402,91202,90250,91413,90032,90042,90061,90270,90041,91495,90245,91403,91606,90059,90249,91401,91501,91207,91206,91504,90261,90022,90247,91754,90201,90222,90091,90260,91208,91411,91803,90040,91030,91404,91407,91408,91409,91410,91470,91482,91496,91499,90506,90280,91605,90267,90266,90262,91436,91353,91031,91105,90248,91416,91426,91801,90272,91804,90504,90278,90202,91405,91123,91756,90223,90224,91802,91896,91899,91046,91714,91715,91352,91103,91716,91021,91316,91020,91755,90254,91102,91109,91110,91114,91115,91116,91117,91118,91121,91124,91125,91126,91129,91182,91184,91185,91188,91189,90220,91101,91406,91106,90640,91012,90747,91412,91214,91108,90746,91778,91402,91356,90239,90221,90240,91776,90723,90242,91043,90241,90503,90661,90662,90507,90508,90509,90510,91770,91775,91357,91104,90502,91331,91199,90660,90501,91334,91041,90277,91343,90749,91337,91003,91771,91772,91001,91385,91335,91333,90290,90805,90895,90745,91346,91395,90671,91107,91325,90706,90610,91040,90606,91733,91364,91371,91327,91328,91329,91345,90505,91780,91731,90264,91042,91341,91330,90707,90810,91365,91340,91007,91396,90710,91306,90807,90717,90712,90711,90714,90651,90652,91734,91735,91324,90650,91367,91305,91308,91309,91303,90601,91025,91394,90607,90608,90609,90670,91006,91066,91077,90602,91372,91024,91011,91732,90806,91392,90713,90748,90274,90744,91302,90702,90701,91344,90755,91746,90605,91023,90703

and i want to be able to format them into a string array

String[] zipcodes = {};

like this

String[] zipcodes = {"90019", "90022", "90006"};

is there a quick way to do this without manually putting quote marks and commas?

3
  • 2
    String.split(","); Commented Dec 30, 2019 at 0:31
  • You said a List of zipcode. Is it a List or a long String? Commented Dec 30, 2019 at 0:34
  • String[] zipCodes = string.split("\\s{0,},\\s{0,}"); Commented Dec 30, 2019 at 1:23

2 Answers 2

1

Use String.split(",")

String str = "90019,90036,90016,90005,90010,90018,90020,90004,90048,90035,90211,90006,90038,90008,90089,90062,90007,90028,90034,90212,90232,90231,90233,90057,90209,90213,90070,90029,90069,90015,90056,90037,90017,90067,90043,90046,90026,90071,90014,90230,90064,90099,90302,90189,90011,90030,90050,90051,90052,90053,90054,90055,90060,90072,90074,90075,90076,90078,90080,90081,90082,90083,90086,90087,90088,90093,90024,90009,90013,90068,90090,90079,90012,90210,90021,90025,90306,90307,90308,90309,90310,90312,90311,90095,90305,91608,90027,90084,90066,90301,90073,90094,90047,91522,91604,90039,90003,90044,91602,90031,91204,91523,90033,90295,90001,90045,90077,91521,90065,90096,90404,90292,90405,90303,90058,90294,90304,90291,91209,91221,91222,91224,91225,91226,91210,91205,90023,91203,91601,91393,91506,91423,90063,90002,90403,90255,91607,91603,91609,91610,91611,91612,91614,91615,91616,91617,91618,90406,90407,90408,90409,90410,90411,90049,91201,91505,91502,90401,90251,90296,90293,91503,91507,91508,91510,91526,90402,91202,90250,91413,90032,90042,90061,90270,90041,91495,90245,91403,91606,90059,90249,91401,91501,91207,91206,91504,90261,90022,90247,91754,90201,90222,90091,90260,91208,91411,91803,90040,91030,91404,91407,91408,91409,91410,91470,91482,91496,91499,90506,90280,91605,90267,90266,90262,91436,91353,91031,91105,90248,91416,91426,91801,90272,91804,90504,90278,90202,91405,91123,91756,90223,90224,91802,91896,91899,91046,91714,91715,91352,91103,91716,91021,91316,91020,91755,90254,91102,91109,91110,91114,91115,91116,91117,91118,91121,91124,91125,91126,91129,91182,91184,91185,91188,91189,90220,91101,91406,91106,90640,91012,90747,91412,91214,91108,90746,91778,91402,91356,90239,90221,90240,91776,90723,90242,91043,90241,90503,90661,90662,90507,90508,90509,90510,91770,91775,91357,91104,90502,91331,91199,90660,90501,91334,91041,90277,91343,90749,91337,91003,91771,91772,91001,91385,91335,91333,90290,90805,90895,90745,91346,91395,90671,91107,91325,90706,90610,91040,90606,91733,91364,91371,91327,91328,91329,91345,90505,91780,91731,90264,91042,91341,91330,90707,90810,91365,91340,91007,91396,90710,91306,90807,90717,90712,90711,90714,90651,90652,91734,91735,91324,90650,91367,91305,91308,91309,91303,90601,91025,91394,90607,90608,90609,90670,91006,91066,91077,90602,91372,91024,91011,91732,90806,91392,90713,90748,90274,90744,91302,90702,90701,91344,90755,91746,90605,91023,90703";
String[] zipcodes = str.split(",");
Sign up to request clarification or add additional context in comments.

Comments

1

What you are looking for is the split() method for Strings

String[] zipcodes = theString.trim().split(",");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.