last day (15 days later) » 

12:59 PM
-1
A: replace all nulls with empty strings in a JSONArray

Dr.SamIn Java , JSONArray Object is considered as String So do like this : for (int i = 0; i < fullNetworkArray.length(); i++) { Object network = fullNetworkArray.get(i); if (network.equals(null)) { fullNetworkArray.put(i, StringUtils.EMPTY); } ...

 
what is infoLines and how you answers differs with the gven one ?
JSONArray is considered as String, this is a wrong assumption
network.equals(null) will never be true, if network is null then you will have a NullPointerException
null.something will always throw a NPE
It's nothing about you, I just preventing people (you included) to make a mistake that can lead in "unspected" bugs. Please consider any comment before to think other are hating you.
 
1:53 PM
@Dr.Sam yep == compare references, equals is a method (it calls == internally)
@Dr.Sam I the answer was deleted. I wish you a good time. Take this as a oportunity for improuve
 
2:26 PM
Please do not annoy other users with repeated notifications, @Dr.Sam. Your last attempt at doing so got flagged as spam and deleted. Usually, that comes with a temporary ban from chat, but I lifted it for you this time.
A single notification will do. The user gets it in their inbox.
 
2:41 PM
@Dr.Sam please red this post and its releated post also
2
Q: Java string null check by != null or !str.equals(null)?

decent guyWhat's the best way to check for not null values in java. String query ="abcd"; query != null vs !query.equals(null). which is better?why?

that is another discussion
you already understand the null.equals(null) issue ?
ok
great
uhmmm
for the code above
if you are initialisating JSONArray fullNetworkArray = new JSONArray()
then even the for will not be executed
you are misunderstanding
for example
if you have a json
a JSONArray containing Strings
{ "Uno", "Dos", "Tres"}
the condition will be false for every item
but if you have
{ "Uno", null, "Tres"}
then the condition will be applied for the second item
on index 1
let me write some code...
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView myTextView = findViewById(R.id.myTextView);
        try {

            JSONArray myJsonArray = new JSONArray();
            myJsonArray.put("Uno");
            myJsonArray.put(null);
            myJsonArray.put("Tres");

            for (int i = 0; i < myJsonArray.length(); i++) {
                Object checkNull = null;
executing that code you will have a crash
but replacing checkNull.equals(null) by checkNull == null it will work fine
hope that helped you
I have to leave
Bye
 

last day (15 days later) »