Properties

5 minutes
Share the link to this page
Copied
  Completed
Java - The Properties Class. Properties is a subclass of Hashtable. It is used to maintain lists of values in which the key is a String and the value is also a String. The Properties class is used by many other Java classes

Transcript

Hello in this Java programming video we are going to take a look at properties. So properties are pretty cool data structure, which essentially allow you to provide a key and a value. So it's a key value pair situation. So let's just dive right into it. A Java dot util dot asterisk like so. And now we want to pull up the file film so I'm just going to essentially Oh, well you'll see what I'm gonna do this is how you create the pup did nothing ordinary he items the creation and naturally add something new films.

And now you provide the key. The key first one is going to Star Wars, my favorite franchises of all time. The value I'm going to pour in is the favorite movie of mine of the franchise. So I know what I will use the original crap for it the revenge and I'm sure there'll be people watching this video they'll probably just jump after I did do the explanation of why I'll put this and they'll be like, Oh, that's not today. Yeah, so let's carry on films. Next one, I'm going to do that man.

And when I say that man I mean the Nolan trilogy, nothing before the door. Also get in the wrong way. Film per hour for the LA franchise. I will. I will put and my favorite movie So it is close between the two towers. And we're trying to do a return of the Return of the King.

But two towers just ages for me. Okay, so now let's just, you know, print out our properties or system filmed like so. print them all out. That's pretty cool. But can we access an individual on here of course we can do on my final four with the tools to do it, you just do films dot get and now you just specify the actual key. So you know one of these, I'll just copy this football star wars.

Yeah. up in here, there we go. It's a Return of the Jedi. If I misspell it, it will just come up as not. Okay, so One last thing I'm gonna show you is how to sort of loop over the entire properties object and just get everything from it. That'd be really useful as well.

So you need to create an iterator iterator I will call it, I need to set it to the properties objects or films key set. dot iterator, iterator for the other built in methods for that's the beauty of Java. Yes, so many crazy methods that are built in, it just makes your life a lot easier. Because the wild I had an extra wallet store another value in our properties, this structure when the string so the string key equals brain and I don't next again the next value in our iterator, which In essentially all of the values from films, you know, all the key values, I should say all of these. So I the next key like you can see right there, and we need to cast it to a string. So we can actually use it when we, you know, get the actual value as well.

And now we're gonna do a simple system, and lab and in here, we are going to put key code and finally, we're gonna print out also the values of films. Okay. Now if we run it, it printed them all out. And that's it. That's it for the properties, data structure. If you have any questions, feel free to reach out, and I look forward to seeing you in the next awesome Java video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.