Answers for "string sentence to array java"

2

how to convert string to array in java

How to convert string to array

import java.util.*; 
  
public class GFG { 
  
    public static void main(String args[]) 
    { 
  
        String str = "GeeksForGeeks"; 
  
        // Creating array and Storing the array 
        // returned by toCharArray() 
        char[] ch = str.toCharArray(); 
  
        // Printing array 
        for (char c : ch) { 
            System.out.println(c); 
        } 
    } 
}
Posted by: Guest on May-20-2020
0

turning a sentence to an array java

String s = "This is a sample sentence.";
String[] words = s.split("\\s+");
for (int i = 0; i < words.length; i++) {
    // You may want to check for a non-word character before blindly
    // performing a replacement
    // It may also be necessary to adjust the character class
    words[i] = words[i].replaceAll("[^\\w]", "");
}
Posted by: Guest on October-21-2020

Code answers related to "string sentence to array java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language