Split Strings Like a Pro in Java: Improve Your Code and Save Time
I have a string in Java that I want to split into two strings. What is the best way to do that? What should I watch out for? Show me a code example. Are there any security concerns I should have about splitting the string.
#IT #Development #SoftwareDevelopment #JavaProgramming #JavaTutorial #AppplicationSecurity #AppSec #appsecurity #informationsecurity #infosec
Chapters
00:00 Introduction
00:31 Overview
01:22 Define the problem
02:46 Coding example using Java String split method
07:58 Coding example using Java regular expressions
11:23 Application security discussion around Java regular expressions
So the question we address in this video is: How to split a string in Java?
Let’s say that we have a string of digits with a dash somewhere in the string
How can we split the string so the first part of the string ends up in one variable and the second part ends up in another variable?
And, if there is no dash in the string, we want to throw an exception
Great question. There are many ways to do so and we will look at a few.
We’ll assume that we are getting our data in a usual Java String
The string class has had a method called split available since JDK 1.4
The split method takes a regular expression and matches the string around the regular expression
It will return the results in a String array
The pattern will be applied as many times as possible in the string, until the end of the string is reached.
There is an overloaded version of the split method that will limit the number of times the string is matched
Let’s assume we have a string like the following:
888-492929
We could invoke the split method on myString in the following way
String [] substring = myString.split(“-“)
The substring array will contain the value of 888 in substring sub 0
And 492929 in substring sub 1
However things don’t always go as planned
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Split Strings Like a Pro in Java: Improve Your Code and Save Time», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.