bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Java/Java Reference
Java•Java Reference

Java String Methods

All String Methods

The String class has a set of built-in methods that you can use on strings.

MethodDescriptionReturn Type
charAt()Returns the character at the specified index (position)char
codePointAt()Returns the Unicode of the character at the specified indexint
codePointBefore()Returns the Unicode of the character before the specified indexint
codePointCount()Returns the number of Unicode values found in a string.int
compareTo()Compares two strings lexicographicallyint
compareToIgnoreCase()Compares two strings lexicographically, ignoring case differencesint
concat()Appends a string to the end of another stringString
contains()Checks whether a string contains a sequence of charactersboolean
contentEquals()Checks whether a string contains the exact same sequence of characters of the specified CharSequence or StringBufferboolean
copyValueOf()Returns a String that represents the characters of the character arrayString
endsWith()Checks whether a string ends with the specified character(s)boolean
equals()Compares two strings. Returns true if the strings are equal, and false if notboolean
equalsIgnoreCase()Compares two strings, ignoring case considerationsboolean
format()Returns a formatted string using the specified locale, format string, and argumentsString
getBytes()Converts a string into an array of bytesbyte[]
getChars()Copies characters from a string to an array of charsvoid
hashCode()Returns the hash code of a stringint
indexOf()Returns the position of the first found occurrence of specified characters in a stringint
intern()Returns the canonical representation for the string objectString
isEmpty()Checks whether a string is empty or notboolean
join()Joins one or more strings with a specified separatorString
lastIndexOf()Returns the position of the last found occurrence of specified characters in a stringint
length()Returns the length of a specified stringint
matches()Searches a string for a match against a regular expression, and returns the matchesboolean
offsetByCodePoints()Returns the index within this String that is offset from the given index by codePointOffset code pointsint
regionMatches()Tests if two string regions are equalboolean
replace()Searches a string for a specified value, and returns a new string where the specified values are replacedString
replaceAll()Replaces each substring of this string that matches the given regular expression with the given replacementString
replaceFirst()Replaces the first occurrence of a substring that matches the given regular expression with the given replacementString
split()Splits a string into an array of substringsString[]
startsWith()Checks whether a string starts with specified charactersboolean
subSequence()Returns a new character sequence that is a subsequence of this sequenceCharSequence
substring()Returns a new string which is the substring of a specified stringString
toCharArray()Converts this string to a new character arraychar[]
toLowerCase()Converts a string to lower case lettersString
toString()Returns the value of a String objectString
toUpperCase()Converts a string to upper case lettersString
trim()Removes whitespace from both ends of a stringString
valueOf()Returns the string representation of the specified valueString

Previous

Java while Keyword

Next

Java String charAt() Method

This chapter

Overview
264

Lessons

546m

Read time

1. Java Keywords2. Java assert Keyword3. Java abstract Keyword4. Java boolean Keyword5. Java break Keyword6. Java byte Keyword7. Java case Keyword8. Java catch Keyword9. Java char Keyword10. Java class Keyword11. Java continue Keyword12. Java default Keyword13. Java do Keyword14. Java double Keyword15. Java else Keyword16. Java enum Keyword17. Java exports Keyword18. Java extends Keyword19. Java final Keyword20. Java finally Keyword21. Java float Keyword22. Java for Keyword23. Java if Keyword24. Java implements Keyword25. Java import Keyword26. Java instanceof Keyword27. Java int Keyword28. Java interface Keyword29. Java long Keyword30. Java module Keyword31. Java native Keyword32. Java new Keyword33. Java package Keyword34. Java private Keyword35. Java protected Keyword36. Java public Keyword37. Java return Keyword38. Java requires Keyword39. Java short Keyword40. Java static Keyword41. Java super Keyword42. Java switch Keyword43. Java synchronized Keyword44. Java this Keyword45. Java throw Keyword46. Java throws Keyword47. Java transient Keyword48. Java try Keyword49. Java var Keyword50. Java void Keyword51. Java volatile Keyword52. Java while Keyword53. Java String Methods54. Java String charAt() Method55. Java String codePointAt() Method56. Java String codePointBefore() Method57. Java String codePointCount() Method58. Java String compareTo() Method59. Java String compareToIgnoreCase() Method60. Java String concat() Method61. Java String contains() Method62. Java String contentEquals() Method63. Java String copyValueOf() Method64. Java String endsWith() Method65. Java String equals() Method66. Java String equalsIgnoreCase() Method67. Java String format() Method68. Java String getBytes() Method69. Java String getChars() Method70. Java String hashCode() Method71. Java String indexOf() Method72. Java String isEmpty() Method73. Java String join() Method74. Java String lastIndexOf() Method75. Java String length() Method76. Java String matches() Method77. Java String offsetByCodePoints() Method78. Java String regionMatches() Method79. Java String replace() Method80. Java String replaceAll() Method81. Java String replaceFirst() Method82. Java String split() Method83. Java String startsWith() Method84. Java String subSequence() Method85. Java String substring() Method86. Java String toCharArray() Method87. Java String toLowerCase() Method88. Java String toString() Method89. Java String toUpperCase() Method90. Java String trim() Method91. Java String valueOf() Method92. Java Math Methods93. Java Math abs() Method94. Java Math acos() Method95. Java Math addExact() Method96. Java Math asin() Method97. Java Math atan() Method98. Java Math atan2() Method99. Java Math cbrt() Method100. Java Math ceil() Method101. Java Math copySign() Method102. Java Math cos() Method103. Java Math cosh() Method104. Java Math decrementExact() Method105. Java Math exp() Method106. Java Math expm1() Method107. Java Math floor() Method108. Java Math floorDiv() Method109. Java Math floorMod() Method110. Java Math getExponent() Method111. Java Math hypot() Method112. Java Math IEEEremainder() Method113. Java Math incrementExact() Method114. Java Math log() Method115. Java Math log10() Method116. Java Math log1p() Method117. Java Math max() Method118. Java Math min() Method119. Java Math multiplyExact() Method120. Java Math negateExact() Method121. Java Math nextAfter() Method122. Java Math nextDown() Method123. Java Math nextUp() Method124. Java Math pow() Method125. Java Math random() Method126. Java Math rint() Method127. Java Math round() Method128. Java Math scalb() Method129. Java Math signum() Method130. Java Math sin() Method131. Java Math sinh() Method132. Java Math sqrt() Method133. Java Math subtractExact() Method134. Java Math tan() Method135. Java Math tanh() Method136. Java Math toDegrees() Method137. Java Math toIntExact() Method138. Java Math toRadians() Method139. Java Math ulp() Method140. Java Output Methods141. Java Output print() Method142. Java Output printf() Method143. Java Output println() Method144. Java Arrays Class145. Java Arrays. compare() Method146. Java Arrays. equals() Method147. Java Arrays. sort() Method148. Java Arrays. fill() Method149. Java Array length Property150. Java ArrayList Methods151. Java ArrayList add() Method152. Java ArrayList add() Method153. Java ArrayList clear() Method154. Java ArrayList clone() Method155. Java ArrayList contains() Method156. Java ArrayList ensureCapacity() Method157. Java ArrayList forEach() Method158. Java ArrayList get() Method159. Java ArrayList indexOf() Method160. Java ArrayList isEmpty() Method161. Java ArrayList iterator() Method162. Java ArrayList lastIndexOf() Method163. Java ArrayList listIterator() Method164. Java ArrayList remove() Method165. Java ArrayList removeAll() Method166. Java ArrayList removeIf() Method167. Java ArrayList replaceAll() Method168. Java ArrayList retainAll() Method169. Java ArrayList set() Method170. Java ArrayList size() Method171. Java ArrayList sort() Method172. Java ArrayList spliterator() Method173. Java ArrayList subList() Method174. Java ArrayList toArray() Method175. Java ArrayList trimToSize() Method176. Java LinkedList Methods177. Java LinkedList add() Method178. Java LinkedList add() Method179. Java LinkedList clear() Method180. Java LinkedList clone() Method181. Java LinkedList contains() Method182. Java LinkedList forEach() Method183. Java LinkedList get() Method184. Java LinkedList getFirst() Method185. Java LinkedList getLast() Method186. Java LinkedList indexOf() Method187. Java LinkedList isEmpty() Method188. Java LinkedList iterator() Method189. Java LinkedList lastIndexOf() Method190. Java LinkedList listIterator() Method191. Java LinkedList remove() Method192. Java LinkedList removeAll() Method193. Java LinkedList removeFirst() Method194. Java LinkedList removeIf() Method195. Java LinkedList removeLast() Method196. Java LinkedList replaceAll() Method197. Java LinkedList retainAll() Method198. Java LinkedList set() Method199. Java LinkedList size() Method200. Java LinkedList sort() Method201. Java LinkedList spliterator() Method202. Java LinkedList subList() Method203. Java LinkedList toArray() Method204. Java HashMap Methods205. Java HashMap clear() Method206. Java HashMap clone() Method207. Java HashMap compute() Method208. Java HashMap computeIfAbsent() Method209. Java HashMap computeIfPresent() Method210. Java HashMap containsKey() Method211. Java HashMap containsValue() Method212. Java HashMap entrySet() Method213. Java HashMap forEach() Method214. Java HashMap get() Method215. Java HashMap getOrDefault() Method216. Java HashMap isEmpty() Method217. Java HashMap keySet() Method218. Java HashMap merge() Method219. Java HashMap put() Method220. Java HashMap putAll() Method221. Java HashMap putIfAbsent() Method222. Java HashMap remove() Method223. Java HashMap replace() Method224. Java HashMap replaceAll() Method225. Java HashMap size() Method226. Java HashMap values() Method227. Java Scanner Methods228. Java Scanner close() Method229. Java Scanner delimiter() Method230. Java Scanner findInLine() Method231. Java Scanner findWithinHorizon() Method232. Java Scanner hasNext() Method233. Java Scanner hasNextBoolean() Method234. Java Scanner hasNextByte() Method235. Java Scanner hasNextDouble() Method236. Java Scanner hasNextFloat() Method237. Java Scanner hasNextInt() Method238. Java Scanner hasNextLine() Method239. Java Scanner hasNextLong() Method240. Java Scanner hasNextShort() Method241. Java Scanner locale() Method242. Java Scanner next() Method243. Java Scanner nextBoolean() Method244. Java Scanner nextByte() Method245. Java Scanner nextDouble() Method246. Java Scanner nextFloat() Method247. Java Scanner nextInt() Method248. Java Scanner nextLine() Method249. Java Scanner nextLong() Method250. Java Scanner nextShort() Method251. Java Scanner radix() Method252. Java Scanner reset() Method253. Java Scanner useDelimiter() Method254. Java Scanner useLocale() Method255. Java Scanner useRadix() Method256. Java File Class Methods257. Java FileInputStream Methods258. Java FileOutputStream Methods259. Java BufferedReader Methods260. Java BufferedWriter Methods261. Java Iterator Interface262. Java Collections Class Methods263. Java System Methods264. Java Errors and Exception Types