课程: Java: Data Structures

What is a data structure?

- [Instructor] So what actually is a data structure? In any application that you write, it doesn't matter what programming language you're using, there will be data in it. And most likely, you'll want to group that data together in some way. Data structures are basically where you store the data together. A simple list is a really common example of a data structure. Say, for example, you have a to-do list application where people can add items to the to-do list. You're going to need somewhere to store the to-do items so you can keep track of them in your app, and somewhere you can retrieve them from later. What you need is a data structure. In this scenario, the to-do items are the data, and then list you put them in is the data structure. So you can think of data structures as a group of things like a group of to-do items, but as well as being a place to put things, they also give you a way to access the data inside them. In the to-do list, we want to be able to access the to-do items, and you'll also want to be able to add items, and delete items from the list. You might also want to iterate over the items and applies some changes to them. Data structures also tell you how the items relate to each other. For example, does it matter what order the things are in or can they be in any random order? Can you have duplicated items in the data structure or do they all have to be unique and different? The answers to these questions will vary for different use cases, and the data structure you choose will be determined by your answers to those questions. The type of data you put in a data structure could be pretty much anything. They could be numbers or strings or billions or bytes, or there could be instances of your own Java classes. Say you have a to-do item Java class, you could create a data structure, and put to-do item objects in there. You could even have a data structure made up of other data structures, for example a list of lists. So say you have a list of food, within that you could have a list of fruit, and a list of vegetables. So data structures, and I use a group data together. They give you a way to access, and modify the data, and they define the relationships between the data.

内容