[Java] How to convert one element of a String type array to an Int type

For example, if you enter employee information as name and age and substitute it into one array using Scanner. yamada 20

Scanner sc = new Scanner( System.in); String[] employee = sc.nextLine();

However, I have to cast it to an Int type even though I want to change my age So use the Integer.parseInt method

int age = Integer.parseInt( employee[1]);

This completes the cast from String type to Int type. For example, if you want to increase one year

int addAge = Integer.parseInt( employee[1] ) + 1;

Will be. Since the numbers in parentheses are arguments, there is no problem with ordinary variables.

Recommended Posts

[Java] How to convert one element of a String type array to an Int type
[Java] How to convert a character string from String type to byte type
How to convert a file to a byte array in Java
How to make a Java array
Convert a Java byte array to a string in hexadecimal notation
How to change a string in an array to a number in Ruby
Initialization with an empty string to an instance of Java String type
I tried to convert a string to a LocalDate type in Java
Sorting a list with an int array as an element (Java) (Comparator)
[Java] Convert Object type null to String type
Cast an array of Strings to a List of Integers in Java
Convert an array of strings to numbers
[Java] How to convert from String to Path type and get the path
How to check for the contents of a java fixed-length string
[Java] How to turn a two-dimensional array with an extended for statement
How to convert an array of Strings to an array of objects with the Stream API
Get the type of an array element to determine if it is an array
[Java] How to use substring to cut out a part of a character string
[Java] How to get to the front of a specific string using the String class
[Android] How to convert a character string to resourceId
Convert a string to a character-by-character array with swift
How to convert a solidity contract to a Java contract class
How to convert a value of a different type and assign it to another variable
How to use an array for a TreeMap key
java: How to write a generic type list [Note]
[Java] How to cut out a character string character by character
[Java] How to erase a specific character from a character string
How to convert A to a and a to A using AND and OR in Java
[Note] [Beginner] How to write when changing the value of an array element in a Ruby iterative statement
Convert String type to Timestamp type
How to convert Java radix
[Java] Convert ArrayList to array
How to initialize Java array
An unsupported Java version How to get rid of errors
[Java] I want to convert a byte array to a hexadecimal number
How to store a string from ArrayList to String in Java (Personal)
[Java] How to use substring to cut out a character string
For Java beginners: List, Map, Iterator / Array ... How to convert?
Convert an array that may be null to a stream
[Ruby] How to batch convert strings in an array to numbers
How to make a Java container
[Java] How to create a folder
[Java] Correct comparison of String type
[Java] Convert array to ArrayList * Caution
How to use Java enum type
[Swift5] How to get an array and the complement of arrays
[Java] Adding an element to the Collection causes a compile error
[Ruby] I want to put an array in a variable. I want to convert to an array
[Convenient to remember !!!] How to convert from LocalDate type to character string and from character string to LocalDate type
How to get the length of an audio file in java
How to increment the value of Map in one line in Java
About the method to convert a character string to an integer / decimal number (cast data) in Java
[Java] How to search for a value in an array (or list) with the contains method
How to make a Java calendar Summary
[Swift] Summary of how to remove elements from an array (personal note)
[java] Summary of how to handle char
How to add a new hash / array
[Introduction to Java] How to write a Java program
Compare the elements of an array (Java)
How to make a Discord bot (Java)
How to output Java string to console screen