Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Introduction to Data Structures | Basic Data Structures
Java Data Structures
course content

Contenido del Curso

Java Data Structures

Java Data Structures

1. Basic Data Structures
2. Additional Data Structures
3. Map
4. enum & Stream API

bookIntroduction to Data Structures

What are Collections, and Why Are They Needed?

Collections in Java are one of the data structures that are used very frequently. A data structure, in turn, is a way of storing various data types.

In simple terms, a collection is a list of data or variables of a specific type.
While arrays are static, meaning they have a fixed size defined during initialization, collections can be thought of as dynamic arrays. They expand as elements are added to them. So, when you add an element to the list, the size of the list increases until it can accommodate all the elements.

Collections can help us understand how a database works because, with collections, we can also store a large amount of data. In collections, we can store objects of different classes. We can even store arrays in collections, which is a very convenient way to store a large amount of data.

Wrappers

To start working with collections, it's worth noting that collections cannot operate with primitive data types. They specifically work with objects. To store a simple number or letter, we need to use a wrapper class for the primitive data type.

Here's a list of wrapper classes for primitive types:

  1. Integer: Wrapper for the int type;
  2. Long: Wrapper for the long type;
  3. Float: Wrapper for the float type;
  4. Double: Wrapper for the double type;
  5. Character: Wrapper for the char type;
  6. Boolean: Wrapper for the boolean type;
  7. Byte: Wrapper for the byte type;
  8. Short: Wrapper for the short type.

These classes provide methods for converting between primitive types and objects, and they offer various methods for working with values, such as comparison, arithmetic operations, and more.

Let's consider a few examples of using wrapper classes:

java

main

copy
1234567891011
package com.example; public class Main { public static void main(String[] args) { Integer wrap = 15; // autoboxing int prim = wrap; // unboxing int result = wrap.compareTo(prim); // using object method System.out.println(result); } }

In the code above, we created an object of the Integer class and initialized it with a regular number. This way, we used autoboxing. Next, we created a primitive int and initialized it with the value of the wrapper. This is called unboxing.

From this, it can be understood that autoboxing is the automatic conversion of a value from a primitive data type to an object of the wrapper class. Unboxing is the automatic conversion of a value from an object of the wrapper class to a primitive data type.

You can also see how we used the comparison method. This comparison method returns 0 if the data are equal, 1 if the left value is greater than the right, and -1 if the left value is less than the right.

Wrapper classes have many different methods; we won't cover all of them now, but you can explore them locally in your IDE.

I suggest practicing a bit and modifying the compareTo() method so that instead of numeric indicators, we get full-text messages telling us which number is greater:

Tarea

Your task is to handle the value returned by the compareTo() method so that instead of 0, information indicates that the values are equal. Instead of 1, information indicates that the left value is greater than the right, and instead of -1, information indicates that the right value is greater than the left.

Note

Implement the upgrade_comparing method to enhance everything correctly and return a value with the String type.

To pass the task check, you must display "The right value is greater" if the value of right_value is greater; "The values are equal" if the values are equal; "The left value is greater" if the value of left_value is greater. The console outputs should be exactly as specified.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 1
toggle bottom row

bookIntroduction to Data Structures

What are Collections, and Why Are They Needed?

Collections in Java are one of the data structures that are used very frequently. A data structure, in turn, is a way of storing various data types.

In simple terms, a collection is a list of data or variables of a specific type.
While arrays are static, meaning they have a fixed size defined during initialization, collections can be thought of as dynamic arrays. They expand as elements are added to them. So, when you add an element to the list, the size of the list increases until it can accommodate all the elements.

Collections can help us understand how a database works because, with collections, we can also store a large amount of data. In collections, we can store objects of different classes. We can even store arrays in collections, which is a very convenient way to store a large amount of data.

Wrappers

To start working with collections, it's worth noting that collections cannot operate with primitive data types. They specifically work with objects. To store a simple number or letter, we need to use a wrapper class for the primitive data type.

Here's a list of wrapper classes for primitive types:

  1. Integer: Wrapper for the int type;
  2. Long: Wrapper for the long type;
  3. Float: Wrapper for the float type;
  4. Double: Wrapper for the double type;
  5. Character: Wrapper for the char type;
  6. Boolean: Wrapper for the boolean type;
  7. Byte: Wrapper for the byte type;
  8. Short: Wrapper for the short type.

These classes provide methods for converting between primitive types and objects, and they offer various methods for working with values, such as comparison, arithmetic operations, and more.

Let's consider a few examples of using wrapper classes:

java

main

copy
1234567891011
package com.example; public class Main { public static void main(String[] args) { Integer wrap = 15; // autoboxing int prim = wrap; // unboxing int result = wrap.compareTo(prim); // using object method System.out.println(result); } }

In the code above, we created an object of the Integer class and initialized it with a regular number. This way, we used autoboxing. Next, we created a primitive int and initialized it with the value of the wrapper. This is called unboxing.

From this, it can be understood that autoboxing is the automatic conversion of a value from a primitive data type to an object of the wrapper class. Unboxing is the automatic conversion of a value from an object of the wrapper class to a primitive data type.

You can also see how we used the comparison method. This comparison method returns 0 if the data are equal, 1 if the left value is greater than the right, and -1 if the left value is less than the right.

Wrapper classes have many different methods; we won't cover all of them now, but you can explore them locally in your IDE.

I suggest practicing a bit and modifying the compareTo() method so that instead of numeric indicators, we get full-text messages telling us which number is greater:

Tarea

Your task is to handle the value returned by the compareTo() method so that instead of 0, information indicates that the values are equal. Instead of 1, information indicates that the left value is greater than the right, and instead of -1, information indicates that the right value is greater than the left.

Note

Implement the upgrade_comparing method to enhance everything correctly and return a value with the String type.

To pass the task check, you must display "The right value is greater" if the value of right_value is greater; "The values are equal" if the values are equal; "The left value is greater" if the value of left_value is greater. The console outputs should be exactly as specified.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 1
toggle bottom row

bookIntroduction to Data Structures

What are Collections, and Why Are They Needed?

Collections in Java are one of the data structures that are used very frequently. A data structure, in turn, is a way of storing various data types.

In simple terms, a collection is a list of data or variables of a specific type.
While arrays are static, meaning they have a fixed size defined during initialization, collections can be thought of as dynamic arrays. They expand as elements are added to them. So, when you add an element to the list, the size of the list increases until it can accommodate all the elements.

Collections can help us understand how a database works because, with collections, we can also store a large amount of data. In collections, we can store objects of different classes. We can even store arrays in collections, which is a very convenient way to store a large amount of data.

Wrappers

To start working with collections, it's worth noting that collections cannot operate with primitive data types. They specifically work with objects. To store a simple number or letter, we need to use a wrapper class for the primitive data type.

Here's a list of wrapper classes for primitive types:

  1. Integer: Wrapper for the int type;
  2. Long: Wrapper for the long type;
  3. Float: Wrapper for the float type;
  4. Double: Wrapper for the double type;
  5. Character: Wrapper for the char type;
  6. Boolean: Wrapper for the boolean type;
  7. Byte: Wrapper for the byte type;
  8. Short: Wrapper for the short type.

These classes provide methods for converting between primitive types and objects, and they offer various methods for working with values, such as comparison, arithmetic operations, and more.

Let's consider a few examples of using wrapper classes:

java

main

copy
1234567891011
package com.example; public class Main { public static void main(String[] args) { Integer wrap = 15; // autoboxing int prim = wrap; // unboxing int result = wrap.compareTo(prim); // using object method System.out.println(result); } }

In the code above, we created an object of the Integer class and initialized it with a regular number. This way, we used autoboxing. Next, we created a primitive int and initialized it with the value of the wrapper. This is called unboxing.

From this, it can be understood that autoboxing is the automatic conversion of a value from a primitive data type to an object of the wrapper class. Unboxing is the automatic conversion of a value from an object of the wrapper class to a primitive data type.

You can also see how we used the comparison method. This comparison method returns 0 if the data are equal, 1 if the left value is greater than the right, and -1 if the left value is less than the right.

Wrapper classes have many different methods; we won't cover all of them now, but you can explore them locally in your IDE.

I suggest practicing a bit and modifying the compareTo() method so that instead of numeric indicators, we get full-text messages telling us which number is greater:

Tarea

Your task is to handle the value returned by the compareTo() method so that instead of 0, information indicates that the values are equal. Instead of 1, information indicates that the left value is greater than the right, and instead of -1, information indicates that the right value is greater than the left.

Note

Implement the upgrade_comparing method to enhance everything correctly and return a value with the String type.

To pass the task check, you must display "The right value is greater" if the value of right_value is greater; "The values are equal" if the values are equal; "The left value is greater" if the value of left_value is greater. The console outputs should be exactly as specified.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

What are Collections, and Why Are They Needed?

Collections in Java are one of the data structures that are used very frequently. A data structure, in turn, is a way of storing various data types.

In simple terms, a collection is a list of data or variables of a specific type.
While arrays are static, meaning they have a fixed size defined during initialization, collections can be thought of as dynamic arrays. They expand as elements are added to them. So, when you add an element to the list, the size of the list increases until it can accommodate all the elements.

Collections can help us understand how a database works because, with collections, we can also store a large amount of data. In collections, we can store objects of different classes. We can even store arrays in collections, which is a very convenient way to store a large amount of data.

Wrappers

To start working with collections, it's worth noting that collections cannot operate with primitive data types. They specifically work with objects. To store a simple number or letter, we need to use a wrapper class for the primitive data type.

Here's a list of wrapper classes for primitive types:

  1. Integer: Wrapper for the int type;
  2. Long: Wrapper for the long type;
  3. Float: Wrapper for the float type;
  4. Double: Wrapper for the double type;
  5. Character: Wrapper for the char type;
  6. Boolean: Wrapper for the boolean type;
  7. Byte: Wrapper for the byte type;
  8. Short: Wrapper for the short type.

These classes provide methods for converting between primitive types and objects, and they offer various methods for working with values, such as comparison, arithmetic operations, and more.

Let's consider a few examples of using wrapper classes:

java

main

copy
1234567891011
package com.example; public class Main { public static void main(String[] args) { Integer wrap = 15; // autoboxing int prim = wrap; // unboxing int result = wrap.compareTo(prim); // using object method System.out.println(result); } }

In the code above, we created an object of the Integer class and initialized it with a regular number. This way, we used autoboxing. Next, we created a primitive int and initialized it with the value of the wrapper. This is called unboxing.

From this, it can be understood that autoboxing is the automatic conversion of a value from a primitive data type to an object of the wrapper class. Unboxing is the automatic conversion of a value from an object of the wrapper class to a primitive data type.

You can also see how we used the comparison method. This comparison method returns 0 if the data are equal, 1 if the left value is greater than the right, and -1 if the left value is less than the right.

Wrapper classes have many different methods; we won't cover all of them now, but you can explore them locally in your IDE.

I suggest practicing a bit and modifying the compareTo() method so that instead of numeric indicators, we get full-text messages telling us which number is greater:

Tarea

Your task is to handle the value returned by the compareTo() method so that instead of 0, information indicates that the values are equal. Instead of 1, information indicates that the left value is greater than the right, and instead of -1, information indicates that the right value is greater than the left.

Note

Implement the upgrade_comparing method to enhance everything correctly and return a value with the String type.

To pass the task check, you must display "The right value is greater" if the value of right_value is greater; "The values are equal" if the values are equal; "The left value is greater" if the value of left_value is greater. The console outputs should be exactly as specified.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 1. Capítulo 1
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
some-alt