Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Here's my problem :
I have this String for instance
[[0,0,1],[1,0,0],[1,1,1]]
And I would like to convert it into an actual
int[][]
What's the best way to proceed ?
Thank you in advance !
The string you have is a lot like JSON format. You can use a JSON parser like gson
https://code.google.com/p/google-gson/
It will be able to parse string variants of lots of things.
The default fromJson might work since you are using pretty simple value types, but you can also try to explicitly set the array type.
Type listType = new TypeToken<Integer[][]>() {}.getType();
Integer[][] yourArray = new Gson().fromJson(text, listType);
You can ignore the first [ and the last ] as they are not making a difference.
The you can split the string by the commas and get a String[]. You just need to iterate through that and fill up your int[][].
Use nested loops and the Integer.parseInt method.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Can someone please explain the use of the following code in Java
private TableColumn<Books, Integer> colId;
I want to know the reason of using <?,?> to declare a variable in Java.
Those are 'Generics'. Specifically, the things inside the brackets are called 'Type Parameters'. It allows different types to be chosen when you create the object or 'variable' as you call it.
So you could have a list of numbers with: new ArrayList<Integer>()
or a list of strings with: new ArrayList<String>()
https://www.tutorialspoint.com/java/java_generics.htm
In your example, it's creating a column to keep track of ids for books. The ids will be ints and the object they are identifying is books. But, you may want another TableColumn (which behaves the same as the Book Id column) but for tracking the titles of the books: TableColumn<Books, String> colTitle
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
i have following issue .
I send JSON like this to backend :
{"n":"dsad","t":"asda","term":"2021-06-26, 2021-06-30"}
I need to send this "term" not like this just like array ->
"term": [
"2021-07-08",
"2021-07-06"
]
How can i do it?
I have angular in frontend and Java as backend.
Thanks for help.
To acheave this you can use the split function in Jacascript and split on the , . This will give an array you can use to replace the term object.
object.term = object.term.replace(" ","").split(",")
Create an interface so you are forced to build the object in the way needed.
export interface InterfaceName {
n: string;
t: string;
term: Date[];
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Good I am trying to create a function that generates new Array, and trying to use a getter method that returns a name for example ArrayD5, ArrayD10 and use these as the name of the new arrays to generate.
I have tried to do this:
int length = 5;
String (SeatIbiza.nombres(length))[] = new String[length];
String nombres (int length) {
return "ArrayD"+length;
}
If you are looking for a way to declare something like e.g.
String "ArrayD" + 2
so that you have a variable
String ArrayD2
then this is not possible in Java. Dynamic naming of variables is not supported.
I don't think if that's possible. The variable names are required to be declared during compile time in JAVA and dynamic naming isn't supported... yet.
Correct me if I'm wrong as I'm still learning about JAVA
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a String and I want convert it to a String array without using a JsonObject.
I searched many topics, but I can't solve my problem.
My String is like:
String str="[{"India":{"State":"Gujarat","City":"Rajkot","Pin":360330,"Place":"AT Rajkot"}}]";
And I want output As Array like:
India
Gujarat
Rajkot
360330
AT Rajkot
How can I get an array like that output, without using jsonObject?
You are asking how to parse JSON. You need to use a JsonObject or another JSON library. If you want to learn how to do this, read the several thousand lines of source code in JsonObject and learn how to write a JSON parser. Then, write a JSON parser, which will do what you want.
In other words, what you are asking is not technically incorrect, but ridiculous.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have the following row in my function:
Collection<Song> songs = a.getListOfSongs();
There are all required annotations in the Song class.
Need to return JSON String using GSON lib.
Thank you!
Use new Gson().toJson(songs). Although when you try to make Song bean from this json, you might have to face some casting issues like, int value would have converted to double, char to string...as GSON uses its intelligence to resolve such types
Gson gson = new Gson();
String json = gson.toJson(songs);