Quantcast
Channel: string to string array conversion in java - Stack Overflow
Browsing index pages (16 articles)
↧

string to string array conversion in java

I have a string="name"; I want to convert into a string array. How do I do it? Is there any java built in function? Manually I can do it but I'm searching for a java built in function. I want an array...

View Article


Answer by Aidanc for string to string array conversion in java

Convert it to type Char? http://www.javadb.com/convert-string-to-character-array

View Article


Answer by thelost for string to string array conversion in java

String array = array of characters ? Or do you have a string with multiple words each of which should be an array element ? String[] array = yourString.split(wordSeparator);

View Article

Answer by f1sh for string to string array conversion in java

String strName = "name"; String[] strArray = new String[] {strName}; System.out.println(strArray[0]); //prints "name" The second line allocates a String array with the length of 1. Note that you don't...

View Article

Answer by Landei for string to string array conversion in java

I guess there is simply no need for it, as it won't get more simple than String[] array = {"name"}; Of course if you insist, you could write: static String[] convert(String... array) { return array; }...

View Article


Answer by rsp for string to string array conversion in java

To start you off on your assignment, String.split splits strings on a regular expression, this expression may be an empty string: String[] ary = "abc".split(""); Yields the array: (java.lang.String[])...

View Article

Answer by finnw for string to string array conversion in java

Assuming you really want an array of single-character strings (not a char[] or Character[]) 1. Using a regex: public static String[] singleChars(String s) { return s.split("(?!^)"); } The zero width...

View Article

Answer by atamanroman for string to string array conversion in java

String data = "abc"; String[] arr = explode(data); public String[] explode(String s) { String[] arr = new String[s.length]; for(int i = 0; i < s.length; i++) { arr[i] = String.valueOf(s.charAt(i));...

View Article


Answer by Frank Hou for string to string array conversion in java

/** * <pre> * MyUtils.splitString2SingleAlphaArray(null, "") = null * MyUtils.splitString2SingleAlphaArray("momdad", "") = [m,o,m,d,a,d] * </pre> * @param str the String to parse, may be...

View Article


Answer by HyperNeutrino for string to string array conversion in java

You could use string.chars().mapToObj(e -> new String(new char[] {e}));, though this is quite lengthy and only works with java 8. Here are a few more methods: string.split(""); (Has an extra...

View Article

Answer by AGéoCoder for string to string array conversion in java

An additional method: As was already mentioned, you could convert the original String "name" to a char array quite easily: String originalString = "name"; char[] charArray =...

View Article

Answer by ccpizza for string to string array conversion in java

Splitting an empty string with String.split() returns a single element array containing an empty string. In most cases you'd probably prefer to get an empty array, or a null if you passed in a null,...

View Article

Answer by fonji for string to string array conversion in java

In java 8, there is a method with which you can do this: toCharArray(): String k = "abcdef"; char[] x = k.toCharArray(); This results to the following array: [a,b,c,d,e,f]

View Article


Answer by Suragch for string to string array conversion in java

Based on the title of this question, I came here wanting to convert a String into an array of substrings divided by some delimiter. I will add that answer here for others who may have the same...

View Article

Answer by Rahul Chaube for string to string array conversion in java

here is have convert simple string to string array using split method. String [] stringArray="My Name is ABC".split(" "); Output stringArray[0]="My"; stringArray[1]="Name"; stringArray[2]="is";...

View Article


Answer by Radhesh Khanna for string to string array conversion in java

Simply Use the .tocharArray() method in java String k = "abc"; char alpha = k.tocharArray(); This should work just fine in JAVA 8

View Article
Browsing index pages (16 articles)


Latest Images