Learn Java Coding From Digital Marketing agencies in Bangalore

So what we can do is we can kind of transform that if we ever need to. So let’s go into that kind of good practice right. So there’s a built-in a function we can use code to locale string. And so just to show that off you know we can tinker around in the console here as well. So let’s say Konst long string equals big string like that. Learn Java Coding From Digital Marketing agencies in Bangalore And then we want to shift-enter there. By the way and I want to cancel that but we want to insert commas so we can do transform actually with you Konst new string equals long string to the low string. And this will detect whatever locale you’re in.

You can give it different locales use if you want to you but in this case, we have a new string. And let’s see internet marketing services in Bangalore. Cancel the log. New string. There we go. We see that it transformed it for us. Originally it didn’t have those commas. So to contrast if you want a long long string it’s a long string. It doesn’t have those commas so we can use this to our advantage. One thing we need to watch out for is sometimes pop is unknown. So we’re going to need to check for that and we can do that in a couple of ways.


One thing I will show you is we can do. Let’s do let pop know we can do if the population equals a known pop equals Population. Else pop equals and population as it is now it’s a string. So we need to transform it into a number and then we need to call two local string on it. So we transform a string into a number. Use this parse into a function to parse it take in the population which is currently a string that is a bunch of numbers and then two local string on it and then in here instead of the population we will represent pop cape. Let’s see if Digital Marketing agencies in Bangalore this works as it should. Quick. Hey, that one has a pop of unknown looks good this one over it added the column in for us.

Pretty cool. And what are we doing we’re doing after the end? Let’s do before. And so it always kind of puts it at the bottom and I just refresh that. Six million is when it’s. Awesome. It works as intended. Digital Marketing agencies in Bangalore And if you were targeting a specific locale you would put an argument into two locales string for example. For example, if you had to target a German audience you would do something like this. Dd. Let’s see what this looks like. If we transformed it to be local to you know the German language quick and instead of commas it starts it makes sense.


If you transform it into Arabic numbers you would do something like this which could be pretty interesting. Let’s see Digital Marketing agencies in Bangalore
Cool. That looks pretty neat. This one is unknown. Yeah. Good stuff. So basically it detects what locale you’re in. And this will detect that I want it to do you know English style formatting. Hauf a couple of times that we go and you know we’re doing an if statement. We can also do something else which is called a turnaround operator. And if you’ve never seen a ternary operator basically you give it it’s like an if statement but you can do it all in one line.

So we could do something like population equals unknown and they use a question mark. So this is kind of your if statement. You can kind of look at it as a backward statement so if a population is unknown do something and use a colon do something else in other words if the population is unknown we will say Pop equals Population otherwise if it’s not unknown then we can put Digital Marketing agencies in Bangalore here and say it and we can kind of condense it down into one line. This is a matter of personal preference right.


This kind of adds level of complexity where it’s a little bit harder to interpret sometimes versus an if statement. So it’s up to you to use it or not. But if you’re looking to kind of put it all in one line this is the way you would want to do it. So population unknown otherwise pops equals. Parse. Int population to locale. A string that’s so let’s see if this works the same way and it should Yeah there we go. It’s working as intended. And there we see an unknown.

WEBVTT The neat thing about a tertiary operator like this recalls that you can evaluate an expression inside this interpellation in six which means instead of doing let pop you can just kind of grab this Scrabble this entire line and we just evaluate that right in hereDigital Marketing agencies in Bangalore. So this is how you can use the turnaround OPERATOR You can’t use an if statement inside this expression statement but you can use a or you OPERATOR So you can say population if the population is unknown.


I’ll just display population otherwise just display the result of this function essentially parse into two locales string. So this is how we can use a turnaround operator. This is where you might want to use one right and so doing it if else imminent declaring another variable. If you want to you could just put this inside your you know your interpellation here. Personal preference again but this should still work if that’s tested out OK all these places have population but in no way, this will work as it should.

So that’s pretty neat in my mind. And let’s keep playing. So there’s an unknown. OK. So moving on let’s expand our example out of it. Right now we’re just going to the API and grabbing one planet. But if we don’t give it a number to grab. For example, if we just do this it’s going to grab a whole bunch of planets and know let’s practice doing that so we can practice looping. So essentially what we’ll do is we’ll grab all the planets we will extract something and then we will just do a loop to invoke dysfunction a bunch of times.

Share This Story

Get our newsletter