About 3,200,000 results
Open links in new tab
  1. How should I copy Strings in Java? - Stack Overflow

    Strings are immutable objects so you can copy them just coping the reference to them, because the object referenced can't change ... So you can copy as in your first example without any problem : String s = "hello"; String backup_of_s = s; s = "bye";

  2. 3 different ways to copy a string in Java - CodeVsColor

    Learn how to copy a string in Java in three different ways. We will learn how to copy a string using direct assignment, using StringBuffer and using String.copyValueOf.

  3. How to Copy a String in Java - Delft Stack

    Feb 2, 2024 · In this article, we will explore various methods to copy a string in Java, each offering unique advantages and use cases. In Java, copying a String can be achieved through a straightforward assignment of one string variable to another.

  4. How to copy from a string to another string in Java?

    Apr 21, 2013 · Use String.substring(...) if you only want some characters. Edit: To combine an existing string with some characters from another string you would use: String anotherString = anotherString + originalString.substring(...); To create a new string with some characters from another string you would use:

  5. Java String copyValueOf() Method - W3Schools

    The copyValueOf() method returns a String that represents the characters of a char array. This method returns a new String array and copies the characters into it.

  6. Java String Copy - DigitalOcean

    Aug 3, 2022 · Here is a short java String copy program to show this behavior. public static void main(String args[]) { String str = "abc"; String strCopy = str; str = "def"; System.out.println(strCopy); // prints "abc" Note that we can perform direct assignment of one variable to another for any immutable object. It’s not limited to just String objects.

  7. Java String Copy Examples

    Sep 5, 2020 · String str = "Hello World"; String strCopy1 = String.copyValueOf(str.toCharArray()); String strCopy2 = String.copyValueOf(str.toCharArray(), 0, str.length()); In this article, we have seen the Java String Copy Examples.

  8. string - Just copy a substring in java - Stack Overflow

    Jul 26, 2012 · Use split(), (it probably internally uses indexOf()) http://www.java-examples.com/java-string-split-example. You just need to split the string using the dot as the separator. String[] split_str = str.split("\\."); split_str will be:

  9. Java Program to Copy String - CodesCracker

    Java Program to Copy String - This article covers multiple programs in Java that copies one string to another. Copy string without using function in Java, Copy string using StringBuffer class in Java, using valueOf(), using copyValueOf() method in Java

  10. How to make copy of a string in Java | Reactgo

    Nov 9, 2020 · To make a copy of a string, we can use the built-in new String() constructor in Java. Example: public class Main { public static void main ( String [ ] args ) { String s = "hello" ; String copy = new String ( s ) ; System . out . println ( copy ) ; } }

  11. Some results have been removed