Question:
How to create array of char arrays in java?
Garfield
2008-11-22 10:43:59 UTC
Also is there already a function that sorts the array?
Four answers:
DadOnline
2008-11-22 11:00:07 UTC
char[][] myArray;



No there is not a builtin function to sort it.

PHP has that but not java.
?
2016-12-16 10:47:38 UTC
Character Arrays In Java
?
2016-05-24 09:26:34 UTC
An ArrayList only supports operations on objects. So instead of using a char, which is not an object, you can use a Character, which is a wrapper class. Basically, it's just an object that holds a char. You can then use your ArrayList like you would any other object type.
deonejuan
2008-11-22 11:08:22 UTC
If you want modern code to do that...

HashMap hm = new HashMap();



otherwise, you use arrays of arrays. in this case, an array of char[] arrays. Without testing it, you might have to use Object[] as the first order array to hole your char[] arrays.



To make a char Array

String s = "This is my spiffy String";

char[] c = s.toCharArray();

// import java.util.Arrays; statement at top of code



Arrays.sort(c); // will sort the primitives char in numeric order

Arrays.sort(Object); would require you define a Comparator



I would have to know more about your code requirements to understand if it was worth it to do a Multi-dim array or refer you to tutorials on the modern code techniques.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...