How to store a string from ArrayList to String in Java (Personal)

background

I was writing a program to convert numbers after the decimal point to binary numbers, and I wanted to handle the numbers added to the list other than the extended for statement.

environment

Eclipse Neon 4.6.3 Java8

Method

String variable name= String.join(Characters you want to concatenate,Array name);

I tried using it

public class forPractice {

    public static void main(String[] args) {

        double x = 0.125;
        List<String> y = new ArrayList<String>();

        while (x > 0) {

            x *= 2;

            if (x >= 1) {
                y.add("1");
                x -= 1;
            } else {
                y.add("0");
            }
        }

        String z = String.join("", y);

        System.out.print("0." + z);

    }
}

Execution result

0.001

Summary

If it was completed on one screen, only the extended for statement was enough, but I felt that the for statement was difficult to handle when creating JSP using Servlet, so I decided to use this as well.

Recommended Posts

How to store a string from ArrayList to String in Java (Personal)
[Java] How to erase a specific character from a character string
[Java] How to convert a character string from String type to byte type
How to display a web page in Java
Code to escape a JSON string in Java
How to get Class from Element in Java
How to write Java String # getBytes in Kotlin?
[Personal memo] How to interact with a random number generator in Java
How to create a Java environment in just 3 seconds
How to jump from Eclipse Java to a SQL file
How to create a data URI (base64) in Java
How to store Rakuten API data in a table
[Java] How to cut out a character string character by character
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java
[Spring Boot] How to get properties dynamically from a string contained in a URL
How to make a Java container
Convert a Java byte array to a string in hexadecimal notation
How to change a string in an array to a number in Ruby
[Java] How to create a folder
[Java] How to use substring to cut out a character string
I tried to convert a string to a LocalDate type in Java
[Java] How to use List [ArrayList]
How to use classes in Java?
How to name variables in Java
How to develop and register a Sota app in Java
How to simulate uploading a post-object form to OSS in Java
How to make a Java array
How to concatenate strings in java
How to implement a job that uses Java API in JobScheduler
How to create a new Gradle + Java + Jar project in Intellij 2016.03
How to store the information entered in textarea in a variable in the method
[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
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
How to insert a video in Rails
How to do base conversion in Java
How to make a Discord bot (Java)
How to output Java string to console screen
How to implement coding conventions in Java
How to embed Janus Graph in Java
Notation to put a variable in a string
Java: How to send values from Servlet to Servlet
How to print a Java Word document
How to get the date in java
Split a string with ". (Dot)" in Java
[Easy-to-understand explanation! ] How to use ArrayList [Java]
How to publish a library in jCenter
Type conversion from java BigDecimal type to String type
How to test a private method in Java and partially mock that method
How to develop from VScode in a remote destination environment or a remote destination container environment
How to get the current date as a string in yyyyMMdd format
[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
How to pass a proxy when throwing REST over SSL in Java
How to get the absolute path of a directory running in Java
[Java] [For beginners] How to insert elements directly in a 2D array
GetInstance () from a @Singleton class in Groovy from Java
Convert to a tag to URL string in Rails