Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
String names = "Peter, John, Andy, David";
String [] splitNames = names.split(",");
System.out.println(Arrays.tostring(splitNames(','));
I am beginner and I am trying to correct the code to the end result of my question listed. I am teaching myself from a book which has no listed details. If someone could assist that would be great. Thank you! I think I am on the right path I am overlooking my mistake.
This is easier to accomplish with the Stream api that was introduced in Java 8:
System.out.println(
Arrays.stream(splitNames)
.collect(Collectors.joining(", ", "{", "}"))
);
Here's a good tutorial for Stream collectors: https://www.baeldung.com/java-8-collectors
Just correct this line:
System.out.println(Arrays.tostring(splitNames(','));
to:
System.out.println(Arrays.toString(splitNames));
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have this JSON example
{ "name": "custom_text" }
My Object look like
public class NameObj {
private String name;
}
And with readValue() method from Jackson can deserialized my json into NameObj.
The real problem is when i don't have "name"
{ [ "custom_text" ] }
How create object in this case? And deserialization is same?
In the example { "names" : [ "custom_text" ] } it does not really
matter if you represent the [ "custom_text" ] as list or array but if
you choose the latter, it would rather be String[] instead of Array[].
Also mind the type erasure if you choose List String . Then you have
to use e.g. TypeReference helpers.
Answer by mle
List String work for me. Thank you mle
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
my code looks like this:
Student jackNapoli = new Student(3, Jack, Napoli, The_Lawyer99#yahoo.com, 19, 85,84,87);
I am trying to create an new object of the Student class. My problem is the # symbol in the email address. How do I get this to not show up as error?
The problem is not in the # symbol.
The way you are passing the parameters to Student, Jack, Napoli and The_Lawyer99#yahoo.com are seen as object.
The compiler might tell you the problem is with the # because it is reserved for annotation in java. However, the real problem is that you probably want to pass these values as string using quotes.
Student jackNapoli = new Student(3, "Jack", "Napoli", "The_Lawyer99#yahoo.com", 19, 85,84,87);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I guess its a rather simple question but i just cant find my mistake.
int[] myIntArray = new int[20];
myIntArray[5] = 5;
int a = myIntArray[5];
TextIO.putf("arr[i]: d%",a );
The error I get is Illegal format string in TextIO.putf() method.
So I assume the value at the index 5 is not an int?
The error message says exactly what the problem is: your format string is wrong. You probably meant %d (or better yet, %d%n to add a newline).
The format string elements are in the form
%[modifiers]type
not
something%
Change d% to %d.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm unable to escape the XML charecters in the Json response.
Here is the JSON response
{"projectId":14,"modificationDate":1379677731000,"projectJsonData":"{"playerConfig":{"autoPlay":true,"initVolume":"50","initFullScreen":false,"size":"container","splashPoster":"defailt.png","projectId":123456},"formList":[{"type":"form","subType":"form-image","position":"inscreen","transition":"comealive-fade","width":50,"zindex":998,"start":12.9125390745513,"end":16.90343280291607,"id":"complexForm1","layout":"formTemplate","imgSrc":"images/birds.jpg","title":"Gannets usually found in Australia..","desc":"The birds that you see in this video are Gannets usually found in Australia and New Zealand. Diving birds are birds which plunge into water to catch fish or other food. They may enter the water from flight, as does the brown pelican or they may dive from the surface of the water. More than likely they evolved from birds already adapted for swimming that were equipped with such adaptations as lobed or webbed feet for propulsion.","button":[{"title":"Gannets","action":"http://en.wikipedia.org/wiki/Gannet","type":"link"},{"title":"Aussie Gannet","action":"http://en.wikipedia.org/wiki/Australasian_Gannet","type":"link"},{"title":"Photography","action":"http://aloneatseaphotography.com.au/8950","type":"link"}],"displayType":"non-intrusive","action":"internal-seek"},{"type":"form","subType":"form-video","start":26.9125390745513,"end":35.90343280291607,"target":"video-container","position":"custom","transition":"comealive-fade","id":"complexForm2","layout":"formTemplate","videoSrc":[{"src":"videos/ocean.mp4","type":"video/mp4","codecs":"vp8,vorbis"},{"src":"videos/ocean.webm","type":"video/webm","codecs":"vp8,vorbis"}],"title":"Slow Motion","desc":"Gannets in super slow-mo","button":[],"displayType":"non-intrusive","tags":"Gannets","action":"internal-seek"},{"type":"form","subType":"form-custom","start":4,"end":10,"target":"video-container","position":"custom","id":"complexForm3","layout":"custom","title":"Gannets","content":"%3Cimg%20style%3D%22position%3Aabsolute%3Bright%3A10%25%3Btop%3A20px%22%20width%3D%22150%22%20height%3D%22150%22%20src%3D%22images%2Fbirds.jpg%22%20%2F%3E","displayType":"intrusive-parallel","desc":"Gannets","tags":"Gannets","action":"internal-seek","animation":"slideIn-600-easeOutBounce"}
I have given partial Json response due to size limitation here.
I have used the following to parse the response
JSONObject jsonProjectDataObject = new JSONObject(
StringEscapeUtils.escapeXml(videoGetResponse.get("projectJsonData").toString()));
Now I get the exception as
org.json.JSONException: Expected ':' after " at character 7 of {"playerConfig":{"autoPlay":true,"initVolume":"50","initFullScreen"
JSON is not XML. Using XML entities is not the appropriate way to escape JSON.
Double quote escaped using XML entities: "
Double quote escaped using JSON : \"
Paste your output here it says its invalid json. Before parsing json check this link