---
title: "String public byte[] getBytes()的使用"
author: "413899327"
date: "2011-04-13T09:27:36Z"
tags: []
categories: ["编程语言"]
slug: "string-public-byte-getbytes"
draft: false
lastmod: "2011-04-13T09:27:36Z"
id: 1000642
url: "https://rogerfederer.iteye.com/blog/1000642"
---

```java


String d1 = " cool "; 
 byte buf  [  ]  = d1.getBytes (  ) ; 
 for  ( int i=0; i < buf.length; i++ )  
  {  
     System.out.println ( " Index " + i + "is : " + buf [ i ]  ) ; 
  }  


```




```java


public void getChars(int srcBegin,
                     int srcEnd,
                     char[] dst,
                     int dstBegin)


//Use getChars (  )  to copy from one string to another string: 
 src = "Good Morning! How are you?"; 
 char dest [  ]  = new char [ src.length (  )  ] ; 
 src.getChars ( 0, src.length (  ) , dest, 0 ) ; 
 System.out.println ( " Source string: " + src ) ; 
 System.out.print ( " Destination string: " ) ; 
 for  ( int i = 0; i  <  dest.length; i++ )  
    System.out.print ( dest [ i ]  ) ; 
  
  
 RESULT: 
 ======= 
    Source string: Good Morning! How are you? 
    Destination string: Good Morning! How are you? 

Read more: http://kickjava.com/777.htm#ixzz1JMVCzfBc




```