Found 33676 Articles for Programming

Converting Strings to Numbers and Vice Versa in Java.

Sravani S
Updated on 26-Feb-2020 09:51:01

2K+ Views

Java lang package provides Integer class which has methods to convert an integer to String and vice versa. You can convert a String to an integer using the parseInt() method and Integer to String using the toString() method.ExampleLive Demopublic class Sample {    public static void main(String args[]){       String str = "1212";       int num = Integer.parseInt(str);       System.out.println(num);       String st = Integer.toString(num);       System.out.println();    } }Output1212

How to Convert Double to String to Double in Java?

V Jyothi
Updated on 26-Feb-2020 09:51:54

335 Views

Java lang package provides a Double class which has methods to convert Double to String and vice versa. You can convert a String to a double using the parseDouble() method and double to String using the toString() methodExampleLive Demopublic class StringDouble {    public static void main(String args[]){       Double data1 = 2.2;       String str = Double.toString(data1);       System.out.println(str);       Double data2 = Double.parseDouble(str);       System.out.println(data2);    } }Output2.2 2.2

Data Conversion Using valueOf() In Java.

Priya Pallavi
Updated on 26-Feb-2020 09:53:23

340 Views

Java String class provides several variants of valueOf() method. These accept various data types and convert them into String.ExampleLive Demopublic class Sample {    public static void main(String args[]){       int i = 200;       float f = 12.0f;       char c = 's';       char[] ch = {'h', 'e', 'l', 'l', 'o'};       String data = String.valueOf(i);       System.out.println(String.valueOf(i));       System.out.println(String.valueOf(f));       System.out.println(String.valueOf(c));       System.out.println(String.valueOf(ch));    } }Output200 12.0 s hello

What is the difference between String.valueOf() and toString() in Java?

Nikitha N
Updated on 26-Feb-2020 09:56:04

2K+ Views

The toString() method of the String class returns itself a string.ExampleLive Demoimport java.io.*; public class Test {    public static void main(String args[]) {       String Str = new String("Welcome to Tutorialspoint.com");       System.out.print("Return Value :");       System.out.println(Str.toString());    } }OutputReturn Value :Welcome to Tutorialspoint.comThe value of method variants of the String class accepts different variables such as integer, float, boolean etc.. and converts them into String.ExampleLive Demopublic class Sample {    public static void main(String args[]){       int i = 200;       float f = 12.0f;       ... Read More

Java string case change sample code examples.

Abhinanda Shri
Updated on 26-Feb-2020 09:49:50

150 Views

You can change the cases using the toUpperCase() and toLowerCase() methods of the String class.ExampleLive Demopublic class Sample {    public static void main(String args[]){       String str = "Hello how are you";       String strUpper = str.toUpperCase();       System.out.println("Lower to upper : "+strUpper);       String strLower = str.toLowerCase();       System.out.println("Upper to lower : "+strLower);    } }OutputLower to upper : HELLO HOW ARE YOU Upper to lower : hello how are you

Making a Java string all uppercase or all lowercase.

Ankitha Reddy
Updated on 20-Sep-2024 21:41:11

2K+ Views

In this program, we will convert a string to both lowercase and uppercase using toLowerCase() and toUpperCase() methods of Java. The toUpperCase() method converts all of the characters in this String to upper case using the rules of the default locale. The toLowerCase() method converts all of the characters in this String to lowercase using the rules of the default locale. Problem Statement Write a Java program that converts strings to lowercase and uppercase using the toLowerCase() and toUpperCase() methods − Input SELF LEARNING CENTER TUTORIALS POINT This is TutorialsPoint www.tutorialspoint.com Output string value = self learning centrestring value = ... Read More

Java program to convert a string to lowercase and uppercase.

Alshifa Hasnain
Updated on 30-Dec-2024 19:15:18

1K+ Views

In Java, converting a string to lowercase or uppercase is a common operation used in text processing, formatting, and case normalization. The String class provides built-in methods to achieve this with ease. This article explores how to use these methods with practical examples, demonstrating step-by-step how to convert strings between uppercase and lowercase. Key Methods toLowerCase(): Converts all characters in a string to lowercase. toUpperCase(): Converts all characters in a string to uppercase. These methods are part of the java.lang.String class and work seamlessly for any string input. Using toLowerCase() ... Read More

Converting to upper case in Java.

Ramu Prasad
Updated on 26-Feb-2020 09:41:12

275 Views

This method has two variants. The first variant converts all of the characters in this String to upper case using the rules of the given Locale. This is equivalent to calling toUpperCase(Locale.getDefault()).The second variant takes a locale as an argument to be used while converting into upper case.ExampleLive Demoimport java.io.*; public class Test {    public static void main(String args[]) {       String Str = new String("Welcome to Tutorialspoint.com");       System.out.print("Return Value :");       System.out.println(Str.toUpperCase());    } }OutputReturn Value :WELCOME TO TUTORIALSPOINT.COM

How to Split a String with Escaped Delimiters?

Sravani S
Updated on 26-Feb-2020 09:42:44

447 Views

The split(String regex) method of the String class splits this string around matches of the given regular expression.ExampleLive Demopublic class Sample{    public static void main(String args[]){       String s = "|A|BB||CCC|||";       String[] words = s.split("\|");       for (String string : words) {          System.out.println(string);       }    } }OutputA BB CCC

How to Split String in Java using Regular Expression?

V Jyothi
Updated on 21-Aug-2024 00:03:07

6K+ Views

In this article, we will learn to split a string in Java using regular expressions. We will be using the split(String regex) method of the String class to split this string around matches of the given regular expression. This method works in the same way as invoking the method i.e. split(String regex, int limit) with the given expression and a limit argument of zero. Therefore, trailing empty strings are not included in the resulting array. Steps to split string in Java using regular expression Following are the steps to split strings in Java using regular expression − ... Read More

Advertisements